New Excel Forum

This forum has been moved to TeachExcel.com

Ask all future questions in the New Excel Forum.

ExcelKey

calculate the difference between 2 dates

Formulas, Functions, Formatting, Charts, Data Analysis, etc.

calculate the difference between 2 dates

Postby Hany0 » Sun Jan 31, 2016 12:54 am

I have a sheet that contains
column A names
column B date of admission
column C date of leave
column D date of death
column Z date of birth

I want to calculate the duration of stay (date of leave - date of admission) if date of death is empty, and
(date of leave - date of death) if there is a date of death.

I have this equation which calculates age,
=DATEDIF($Z5,TODAY(),"Y") & " Years, " & DATEDIF($Z5,TODAY(),"YM") & " Months, " & DATEDIF

($Z5,TODAY(),"MD") & " Days"

can it be modified to satisfy my need, or is there another formula to use?
  • 0

Hany0
Rookie
 
Posts: 11
Joined: Jan 8, 2016
Reputation: 0
Excel Version: 2003

Re: calculate the difference between 2 dates

Postby Beattle Juice » Sun Jan 31, 2016 7:22 am

i am a newb at some of this i cant seam to get my questions right for anybody to understand most the time and i dont know enough on most of this to understand what others are asking but if you can post what you have or are looking for might help i will attach a sheet i was working on with some date junk i was going to use to figure birthdays age and how old a person is or would be if still alive if that will help you
  • 0

You do not have the required permissions to view the files attached to this post.
Just asking the right question the right way is the biggest problem to getting the right answer...with that said LOOKs like I got some problems. LOL
Beattle Juice
Rookie
 
Posts: 13
Joined: Jan 18, 2016
Location: Alaska
Reputation: 0
Excel Version: 13 & 2007

Re: calculate the difference between 2 dates

Postby Beamer » Mon Feb 01, 2016 12:05 am

In cell F2:
Code: Select all
=IF(D2="",C2-B2,D2-B2)
  • 0

You do not have the required permissions to view the files attached to this post.
Beamer
Excel Junkie
 
Posts: 217
Joined: Oct 3, 2014
Location: New South Wales, Australia
Reputation: 31
Excel Version: 2010

Re: calculate the difference between 2 dates

Postby Hany0 » Mon Feb 01, 2016 3:22 am

Thank you, but I need the duration of stay to be in years, months, and days; not just days
  • 0

Hany0
Rookie
 
Posts: 11
Joined: Jan 8, 2016
Reputation: 0
Excel Version: 2003

Re: calculate the difference between 2 dates

Postby Beamer » Mon Feb 01, 2016 6:16 am

ok, try this in F2:
Code: Select all
=DATEDIF($B2,MAX(C2,D2),"Y") & " Years, " & DATEDIF($B2,MAX(C2,D2),"YM") & " Months, " & DATEDIF($B2,MAX(C2,D2),"MD") & " Days"


Edit: Of course, this formula is running on the assumption that if Leave or Death has a date then the other will be blank.
Edit2: And also, I (maybe incorrectly) assumed that where in your original post you had "(date of leave - date of death)" you actually meant "(date of death - date of admission)".
Edit3: Uploaded new file with formula in case those last 2 assumptions of mine were wrong :)
  • 1

You do not have the required permissions to view the files attached to this post.
Beamer
Excel Junkie
 
Posts: 217
Joined: Oct 3, 2014
Location: New South Wales, Australia
Reputation: 31
Excel Version: 2010

Re: calculate the difference between 2 dates

Postby Hany0 » Wed Feb 03, 2016 12:24 am

Thank you, this answers my question. Yes I meant (date of admission - date of death) and (date of admission - date of leave if date of death is empty).

I also need to calculate the duration of stay, if both date of death and date of leave are empty, to be (date of admission - today)
  • 0

Hany0
Rookie
 
Posts: 11
Joined: Jan 8, 2016
Reputation: 0
Excel Version: 2003

Re: calculate the difference between 2 dates

Postby Beamer » Wed Feb 03, 2016 3:18 am

Thankyou for the rep....much appreciated :)

Try this in cell F2:
Code: Select all
=DATEDIF($B2,MIN(C2,D2,TODAY()),"Y") & " Years, " & DATEDIF($B2,MIN(C2,D2,TODAY()),"YM") & " Months, " & DATEDIF($B2,MIN(C2,D2,TODAY()),"MD") & " Days"
  • 1

Beamer
Excel Junkie
 
Posts: 217
Joined: Oct 3, 2014
Location: New South Wales, Australia
Reputation: 31
Excel Version: 2010

Re: calculate the difference between 2 dates

Postby Hany0 » Thu Feb 04, 2016 12:12 am

Thank you very very much, this is exactly what I need.
  • 0

Hany0
Rookie
 
Posts: 11
Joined: Jan 8, 2016
Reputation: 0
Excel Version: 2003

Re: calculate the difference between 2 dates

Postby Beamer » Thu Feb 04, 2016 12:35 am

You are most welcome, very glad I could help.
  • 0

Beamer
Excel Junkie
 
Posts: 217
Joined: Oct 3, 2014
Location: New South Wales, Australia
Reputation: 31
Excel Version: 2010


Return to General Excel Questions

Who is online

Users browsing this forum: No registered users and 106 guests

cron