From number of days to Years, months and days DATEDIFF madness!!

zozew

New Member
Joined
Mar 15, 2019
Messages
21
Hi Everybody,

I have this great little sheet doing some calculations with VBA and excel formulas. All is well until I decided to convert the resulting days into yers months and days..

=DATEDIF(0,3675,"y") & " years, " & DATEDIF(0,3675,"ym")&" months, " & DATEDIF(0,3675,"md")&" days"

And the result is below...all look great right....NO!!!! :) its supposed to be 25 days not 22!!!
10 years, 0 months, 22 days
(the 3675 above comes from a cell D35)

I've checked with various calculators on google and the resulting days should be 25

Can anyone please help me keep some of my hair....

Much appreciated and
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You sure about that?

8 years has to be 2922 days (365x8 + 2), 2 will be either 730 (365x2) or 731 (365x2 + 1), leaving 23 or 22 days as the balance
 
Upvote 0
Try: (I imagined it now, not very tested, may not work as expected or in all situations):
A1 = Date 1
B1 = Date 2
A2 formula (years) =DATEDIF(A1,B1,"y")
B2 formula (months) =DATEDIF(EDATE(A1,A2*12),B1,"m")
C2 formula (days) =DATEDIF(EDATE(EDATE(A1,A2*12),B2),B1,"d")
 
Upvote 0
Can you decipher the reason why this is....some kind of leap year thing?? or...would be nice to be able to have an argument for one or the other when I start to debate this haha
 
Upvote 0
Cool! ill try this...

So if I only have one date/number basically A1 should be 0 then

Try: (not tested, may not work as intended):
A1 = Date 1
B1 = Date 2
A2 formula (years) =DATEDIF(A1,B1,"y")
B2 formula (months) =DATEDIF(EDATE(A1,A2*12),B1,"m")
C2 formula (days) =DATEDIF(EDATE(EDATE(A1,A2*12),B2),B1,"d")
 
Upvote 0
Datadif is used like =datadif(date1;date2;"y or m or a").
The diference between date 0 (1/1/1900) and date 3675 (22/1/1910) is 3675 days.
I don't know the technical details of this function or the date count for this period. Sorry.
Maybe someone else can help.
 
Upvote 0
actually there are 3 more functions MD YM YD

excel_datedif_function.png
 
Upvote 0

Forum statistics

Threads
1,214,851
Messages
6,121,931
Members
449,056
Latest member
denissimo

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