+ Reply to Thread
Results 1 to 14 of 14

Calculating length of time based on one of two dates

  1. #1
    Registered User
    Join Date
    01-26-2018
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    6

    Calculating length of time based on one of two dates

    Hi,
    Hit a brick wall with Excel 2007, I know embarrassing that we are still using it.

    I am trying to monitor the length of time someone is on a treatment for based from a start date to today or an end date.

    I am looking for the time in months.

    I have used this to calculate the time from start to present

    =(YEAR(NOW())-YEAR(J6))*12+MONTH(NOW())-MONTH(J6)

    I have the following columns,

    Status Date of Death Date started Date stopped Total Length on treatment Current length on Treatment


    I would like either Total Length on Treatment or Current Length on Treatment not both running at the same time

    I have tried various IF functions but just cannot get it to work.

    Your input is greatly appreciated.
    Oh and to complicate matters we cannot have any macros. Not allowed in the organisation.

    Cheers.

  2. #2
    Banned User!
    Join Date
    09-26-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    607

    Re: Calculating length of time based on one of two dates

    Hello maybe this will do it:

    =IF(B2<>"",DATEDIF(A2,B2,"m"),DATEDIF(A2,NOW(),"m"))

    A2 start date
    B2 end date

    If no end date it uses today.
    Last edited by Billy Spivy; 01-26-2018 at 07:39 AM.

  3. #3
    Banned User!
    Join Date
    09-26-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    607

    Re: Calculating length of time based on one of two dates

    This is revised for the column so it accounts for no start date:

    =IF(A2<>"",IF(B2<>"",DATEDIF(A2,B2,"m"),DATEDIF(A2,NOW(),"m")),"")

  4. #4
    Registered User
    Join Date
    01-26-2018
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    6

    Re: Calculating length of time based on one of two dates

    Thank you.
    That does work but I was wanting to be able to distinguish between those on treatment and those off treatment.
    I could try conditional formatting but is there any way to do this with a whole sheet?
    Cheers

  5. #5
    Banned User!
    Join Date
    09-26-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    607

    Re: Calculating length of time based on one of two dates

    maybe split it in 2 columns one for current and one for ended?

  6. #6
    Registered User
    Join Date
    01-26-2018
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    6

    Re: Calculating length of time based on one of two dates

    I tried that, but to save confusion I did not want both columns to be populated and that is where I ran into difficulties.

  7. #7
    Banned User!
    Join Date
    09-26-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    607

    Re: Calculating length of time based on one of two dates

    How else would you logically determine if it is current or not?

  8. #8
    Registered User
    Join Date
    01-26-2018
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    6

    Re: Calculating length of time based on one of two dates

    I thought that if the date was not entered into the date stopped column then we could use today as the date in the current length of treatment column to give us the on-going duration in months
    and
    if there was a stop date then there would be a duration in months in the total length of treatment column.
    If that made any sense
    What you gave me works and I will use it, thanks

  9. #9
    Banned User!
    Join Date
    09-26-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    607

    Re: Calculating length of time based on one of two dates

    Perhaps a highlight rule that will show red when it ends?

  10. #10
    Banned User!
    Join Date
    09-26-2017
    Location
    USA
    MS-Off Ver
    2010
    Posts
    607

    Re: Calculating length of time based on one of two dates

    Maybe try something like the example :
    Attached Files Attached Files

  11. #11
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,452

    Re: Calculating length of time based on one of two dates

    How about this.
    E2=IF(F2="",DATEDIF(C2,D2,"m"),"")
    F2=IF(OR(D2>=TODAY(),D2=""),DATEDIF(C2,TODAY(),"m"),"")

    Untitled.png
    Quang PT

  12. #12
    Registered User
    Join Date
    01-26-2018
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    6

    Re: Calculating length of time based on one of two dates

    excellent, almost there bebo.
    Small challenge is when there is no data in the date started column the current length of treatment defaults to 1416 months.
    I had that before and it drove me crazy because it was so untidy The length on treatment defaulting to 0 is just about ok.
    Billy, I will have to wait until I get home as IT security won't let me download it

  13. #13
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,452

    Re: Calculating length of time based on one of two dates

    If no date started, try:
    E2=IF(C2="","",IF(F2="",DATEDIF(C2,D2,"m"),""))
    F2=IF(C2=","",IF(OR(D2>=TODAY(),D2=""),DATEDIF(C2,TODAY(),"m"),""))

  14. #14
    Registered User
    Join Date
    01-26-2018
    Location
    Scotland
    MS-Off Ver
    2007
    Posts
    6

    Re: Calculating length of time based on one of two dates

    Hi Bebo,
    I am getting an error message to do with "m" I cannot work it out.
    Cheers.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. show elapsed count from two fields
    By alyssaross in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-26-2015, 12:39 PM
  2. Calculating the length, start, and end dates of a series of events
    By CharlieDog in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-03-2014, 04:53 PM
  3. Calculating time length based on cell references
    By ChrisSacto in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-09-2013, 05:15 PM
  4. Calculating dates and time
    By shyam sundar in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-22-2013, 03:02 AM
  5. Please Help - Calculating time between two dates
    By Fryguy22 in forum Excel General
    Replies: 3
    Last Post: 08-16-2012, 02:32 PM
  6. [SOLVED] Calculating a future dates based on dates or birth.
    By CDobby in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 07-31-2012, 11:22 AM
  7. How do I find the length of time (Years & Months) between 2 dates
    By David Picken in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 03-23-2006, 04:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1