datedif problem

  • Thread starter Thread starter Legacy 65404
  • Start date Start date
L

Legacy 65404

Guest
Hi all... I think I have a problem....

I used a datedif between the dates: 03/11/1986 and 03/10/1988, and it returned me 1 year, 11 months and 28 days!!! (it should return 29 days!!)

when I tested, I put between 03/11/1986 and 03/11/1988 and returned 2 whole years, what is correct...

It may have happened because 1986 is a leap year... but I don't know what to do...
do you guys have any clue??

thx all in advance...

(please help...)
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
datedif (using the "d") interval gives me the same result as subtracting the two dates (which of course it should). What exactly do you think is wrong?

Gene, "The Mortgage Man", Klein
 
Upvote 0
first... I was mistaken about being leap year... sorry... it's not the problem...
let me see if I can explain what happened:

I use 3 cells, one for year, one for month and one for day
year: =datedif(03/11/1986,03/10/1988,"y")
month: =datedif(03/11/1986,03/10/1988,"ym")
day: =datedif(03/11/1986,03/10/1988,"md")

and it returned like this:
year: 1 (right)
month: 11 (right)
day: 28 (wrong) - should be 29...

when i put:
year: =datedif(03/11/1986,03/11/1988,"y")
month: =datedif(03/11/1986,03/11/1988,"ym")
day: =datedif(03/11/1986,03/11/1988,"md")
(between 03/11/1986 and 03/11/1988)

it comes:
year = 2
month = 0
day = 0

I dont know if I could be clear here... sorry if I didn't...
and thanks for the help
 
Upvote 0
First of all, why are you saying the 11 is right? I mean it is, in the sense that datedif is returning what the "documentation" says it should, but there are clearly more than 11 months in the interval that you choose.

The only way you are going to get consistent results is the way I did it. Use the "d" interval - that will be the same as subtracting the two dates.

Gene, "The Mortgage Man", Klein
 
Upvote 0
This is the behaviour I would expect from Datedif

If you use

=datedif(03/11/1986,03/10/1988,"md")

then 23 whole months from 03/11/1986 will take you until 02/11/1988

Because 1988 is a leap year then there are 28 days from 02/11/1988 until

03/10/1988, hence formula returns 28
 
Upvote 0
yap barry... I knew I had a leap day... lol...

but how can i do? I need the cells to be like the whole date, so that's why I used three different uses of datedif,
I need it to return - 1 year, 11 months and 29 days passed...
do i have to check if its a leap year and add 1 day? this is what I was afraid... more things to think...
 
Upvote 0
You want to use the "y", "m", and "d" intevals and then subtract from the months the number of months in the year interval and subtract from the days the number of days in the y and m interval (this part is where the leap year logic comes in)

I'm off to "shul" but I will check later, if no one posts a formula by tommorow I will.

Gene, "The Mortgage Man", Klein
 
Upvote 0

Forum statistics

Threads
1,225,072
Messages
6,182,695
Members
453,132
Latest member
nsnodgrass73

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