Date Difference

kparadise

Board Regular
Joined
Aug 13, 2015
Messages
186
Hello.

I need to find the Years, Months, and Days between two dates.

Caveat (1); if those values equal zero, I do not want them to display, so I came up with the below which is working great.

Code:
=IF(DATEDIF(W3,Z3,"y"),DATEDIF(W3,Z3,"y")&" YEARS, ","") &
IF(DATEDIF(W3,Z3,"ym"), DATEDIF(W3, Z3, "ym") &" MONTHS, ", "") &
IF(DATEDIF(W3,Z3,"md"), DATEDIF(W3, Z3, "md") &" DAYS", "")

Caveat (2); this is were I need help. I only need the YEARS description once the difference hits 36 months. If the difference is less than 36 months, I do not want the YEARS; I would just need the value in Months and Days. Once it hits 36 Months, then I want the YEARS/MONTHS/DAYS value.

i.e.
11 MONTHS, 20 DAYS
9, YEARS, 10 MONTHS, 13 DAYS
18 MONTHS
17 MONTHS, 16 DAYS
33 MONTHS, 1 DAYS
3 YEARS, 6 DAYS
4 YEARS, 1 MONTHS, 4 DAYS

Caveat (3); Is there a way to use the plural form of MONTH(S) and DAY(S) only when necessary? If it is greater than 1, use the plural.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
It's just adding IF formulas one after another so try something along these lines:
Excel Formula:
=IF(DATEDIF(B3,C3,"m")>36,
DATEDIF(B3,C3,"y")&" years",
IF(DATEDIF(B3,C3,"m"),
DATEDIF(B3,C3,"m")&" month"&
IF(DATEDIF(B3,C3,"m")>1,"s",""),"")&
IF(DATEDIF(B3,C3,"md"),
IF(DATEDIF(B3,C3,"m"),", ","")&
DATEDIF(B3,C3,"md")&" day"&
IF(DATEDIF(B3,C3,"md")>1,"s",""),""))
 
Upvote 0
It's just adding IF formulas one after another so try something along these lines:
Excel Formula:
=IF(DATEDIF(B3,C3,"m")>36,
DATEDIF(B3,C3,"y")&" years",
IF(DATEDIF(B3,C3,"m"),
DATEDIF(B3,C3,"m")&" month"&
IF(DATEDIF(B3,C3,"m")>1,"s",""),"")&
IF(DATEDIF(B3,C3,"md"),
IF(DATEDIF(B3,C3,"m"),", ","")&
DATEDIF(B3,C3,"md")&" day"&
IF(DATEDIF(B3,C3,"md")>1,"s",""),""))
This is defiantly close; but when using this formula; when the months are greater than 36, it is not providing the MONTH and DAY vaules... it is just showing the YEAR value. i.e. It should be 9 YEARS, 1 MONTH, 25 DAYS..... but this formula only gives: 9 YEARS.
 
Upvote 0
This is defiantly close; but when using this formula; when the months are greater than 36, it is not providing the MONTH and DAY vaules... it is just showing the YEAR value. i.e. It should be 9 YEARS, 1 MONTH, 25 DAYS..... but this formula only gives: 9 YEARS.
 
Upvote 0
Your profile does not show the version of Excel that you are using.
Please edit your profile.
If you have 365, review and edit the following.
Once you have the result that you require, you can combine the two suggestions.

Let_a.xlsm
ABCD
1
2
31-Jan-2130-Jun-215 months,29 days
41-Jan-212-Feb-2325 months,1 day
51-Jan-212-Feb-309 years, 1 month,1 day
61-Jan-2118-Aug-309 years, 7 months, 17 days
7
2a
Cell Formulas
RangeFormula
D3:D4D3=LET(Mo,DATEDIF(B3,C3,"m"),Da,DATEDIF(B3,C3,"md"),IF(Mo<36,IF(Mo,Mo&" month"&IF(Mo>1,"s,",""))&Da&" day"&IF(Da>1,"s","")))
D5:D6D5=LET(Yr,DATEDIF(B5,C5,"y"),Ym,DATEDIF(B5,C5,"ym"),Da,DATEDIF(B5,C5,"md"),Yr&" years, "&IF(Ym,Ym&" month"&IF(Ym>1,"s, ",",")&IF(Da,Da&" day"&IF(Da>1,"s",""))))
 
Upvote 0
Your profile does not show the version of Excel that you are using.
Please edit your profile.
If you have 365, review and edit the following.
Once you have the result that you require, you can combine the two suggestions.

Let_a.xlsm
ABCD
1
2
31-Jan-2130-Jun-215 months,29 days
41-Jan-212-Feb-2325 months,1 day
51-Jan-212-Feb-309 years, 1 month,1 day
61-Jan-2118-Aug-309 years, 7 months, 17 days
7
2a
Cell Formulas
RangeFormula
D3:D4D3=LET(Mo,DATEDIF(B3,C3,"m"),Da,DATEDIF(B3,C3,"md"),IF(Mo<36,IF(Mo,Mo&" month"&IF(Mo>1,"s,",""))&Da&" day"&IF(Da>1,"s","")))
D5:D6D5=LET(Yr,DATEDIF(B5,C5,"y"),Ym,DATEDIF(B5,C5,"ym"),Da,DATEDIF(B5,C5,"md"),Yr&" years, "&IF(Ym,Ym&" month"&IF(Ym>1,"s, ",",")&IF(Da,Da&" day"&IF(Da>1,"s",""))))

So I would need to use two different formulas? Is there a way to combine them into one?
 
Upvote 0
"Once you have the result that you require, you can combine the two suggestions."

You can use if < 36 months formula, else formula
 
Upvote 0
I included examples below. I would probably just use a UDF.

Cell Formulas
RangeFormula
D3:D6D3=LET(Yr,DATEDIF(B3,C3,"y"),Ym,DATEDIF(B3,C3,"ym"),Da,DATEDIF(B3,C3,"md"),IF(OR(B3=C3,C3<B3),"",IF(Yr<3,"",Yr)&IF(Yr>=3," years, ","")&IF(Ym+(Yr<3)*Yr*12,Ym+(Yr<3)*Yr*12&" month")&IF(Ym+(Yr<3)*12>1,"s,", " ")&IF(Da,Da&" day","")&IF(Da>1,"s","")))
E3:E6E3=LET(Yr,DATEDIF(B3,C3,"y"),Ym,DATEDIF(B3,C3,"ym"),Da,DATEDIF(B3,C3,"md"),IF(OR(B3=C3,C3<B3),"",IF(Yr<3,"",Yr)&IF(Yr>=3," years ","")&IF(Ym+(Yr<3)*Yr*12,Ym+(Yr<3)*Yr*12&" month","")&IF(Ym+(Yr<3)*12>1,"s ", " ")&IF(Da,Da&" day","")&IF(Da>1,"s","")))
F3:F6F3=IF(DATEDIF(B3,C3,"y")<3,LET(Mo,DATEDIF(B3,C3,"m"),Da,DATEDIF(B3,C3,"md"),IF(Mo,Mo&" month"&IF(Mo>1,"s ",""))&IF(Da,Da&" day","")&IF(Da>1,"s","")),LET(Yr,DATEDIF(B3,C3,"y"),Ym,DATEDIF(B3,C3,"ym"),Da,DATEDIF(B3,C3,"md"),Yr&" years "&IF(Ym,Ym&" month"&IF(Ym>1,"s "," ")&IF(Da,Da&" day"&IF(Da>1,"s","")))))
 
Upvote 0
I included examples below. I would probably just use a UDF.

Cell Formulas
RangeFormula
D3:D6D3=LET(Yr,DATEDIF(B3,C3,"y"),Ym,DATEDIF(B3,C3,"ym"),Da,DATEDIF(B3,C3,"md"),IF(OR(B3=C3,C3<B3),"",IF(Yr<3,"",Yr)&IF(Yr>=3," years, ","")&IF(Ym+(Yr<3)*Yr*12,Ym+(Yr<3)*Yr*12&" month")&IF(Ym+(Yr<3)*12>1,"s,", " ")&IF(Da,Da&" day","")&IF(Da>1,"s","")))
E3:E6E3=LET(Yr,DATEDIF(B3,C3,"y"),Ym,DATEDIF(B3,C3,"ym"),Da,DATEDIF(B3,C3,"md"),IF(OR(B3=C3,C3<B3),"",IF(Yr<3,"",Yr)&IF(Yr>=3," years ","")&IF(Ym+(Yr<3)*Yr*12,Ym+(Yr<3)*Yr*12&" month","")&IF(Ym+(Yr<3)*12>1,"s ", " ")&IF(Da,Da&" day","")&IF(Da>1,"s","")))
F3:F6F3=IF(DATEDIF(B3,C3,"y")<3,LET(Mo,DATEDIF(B3,C3,"m"),Da,DATEDIF(B3,C3,"md"),IF(Mo,Mo&" month"&IF(Mo>1,"s ",""))&IF(Da,Da&" day","")&IF(Da>1,"s","")),LET(Yr,DATEDIF(B3,C3,"y"),Ym,DATEDIF(B3,C3,"ym"),Da,DATEDIF(B3,C3,"md"),Yr&" years "&IF(Ym,Ym&" month"&IF(Ym>1,"s "," ")&IF(Da,Da&" day"&IF(Da>1,"s","")))))
This is not working, I am getting a NAME error.

,LET(Mo,DATEDIF(B3,C3,"m")

That first section is causing the error.
 
Upvote 0
Quote from post #5
Your profile does not show the version of Excel that you are using.
Please edit your profile.
If you have 365, review and edit the following.
Once you have the result that you require, you can combine the two suggestions.


Do you have Excel 365 and the Let function?
Did the previous suggestions work for you?
Did the other examples work for you?

If you have the Let function, click on the icon below the F(x) in my post with the suggestions and post into
a new clean sheet. Then review the formulas.
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top