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
 
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.
Thank you very much! ill keep digging
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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.
Ahhhhh i think i know why now....like you mention it treats the 3675 days as a real date when in fact its only a number of days for me..so I really want to convert it from a number of days to y, m and d with no leap years or other strangely date affecting things....
 
Upvote 0
See this detail on the page above:
"MD"The difference between the days in start_date and end_date. The months and years of the dates are ignored.
Important: We don't recommend using the "MD" argument, as there are known limitations with it. See the known issues section below.
 
Upvote 0
Ahhhhh i think i know why now....like you mention it treats the 3675 days as a real date when in fact its only a number of days for me..so I really want to convert it from a number of days to y, m and d with no leap years or other strangely date affecting things....
Yes serial date, not number of days.
 
Upvote 0
It's a funny problem. Starting at date 0 here are the days per year. (1900 with the extra day 0 for Sat 0 Jan 1900 for the value 0)

21 days are needed to get to your original 3675.

*original suspicion was leap years started earlier in the century, but that was the 1700's


EDIT: no it's not, thought you had 25 for a sec...

yeardays per year
1900​
367​
1901​
365​
1902​
365​
1903​
365​
1904​
366​
1905​
365​
1906​
365​
1907​
365​
1908​
366​
1909​
365​
3654​
total days
3675​
plus 21
 
Upvote 0
Yes serial date, not number of days.


My simple solution or kinda solution...

I have to divide 365 with 12, use the 30.416 result, and then the remaining number convert that into days rounded up...then it kinda works :)

so..

3675 days / 30.416 = 120.8246 months

0.8246 x 30.416 = 25.081 so 25 days

10years, 0 months, 25 days
 
Upvote 0
It's a funny problem. Starting at date 0 here are the days per year. (1900 with the extra day 0 for Sat 0 Jan 1900 for the value 0)

21 days are needed to get to your original 3675.

*original suspicion was leap years started earlier in the century, but that was the 1700's


EDIT: no it's not, thought you had 25 for a sec...

yeardays per year
1900​
367​
1901​
365​
1902​
365​
1903​
365​
1904​
366​
1905​
365​
1906​
365​
1907​
365​
1908​
366​
1909​
365​
3654​
total days
3675​
plus 21
yeah you're right...i was looking at it totally wrong....thanks!
 
Upvote 0
now im trying to get the years months and days separated..hmmm any suggestion how to do that..

years is pretty simple I can round that to whole numbers but months/days is trickier...

3675 days / 30.416 = 120.8246 months

that's 10 full years and 0 months and 0.8246 days

then to get the 0.8246 x 30.416 is 25.08 rounded down to 25 days

my brain is starting to melt slightly...how do I get the months and then all into a formula....?
 
Upvote 0

Forum statistics

Threads
1,216,434
Messages
6,130,597
Members
449,584
Latest member
c_clark

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