May 05 2021 12:31 AM
Hello,
I'm working at an application (internal use) requiring compatibility with the serial numbers generated by Excel for date values. During the testing phase, I've noticed strange issues (failing tests) which I've taken as my application's errors. Then I've created a table and I've noticed a strange behavior of the DATEDIF Excel function when using YD unit and MD unit (at least, this one is documented), sometimes the manual calculation of the difference between the days of the years (the E column in the attached picture) gives a different result than the DATEDIF function. Where am I wrong?
May 05 2021 02:37 AM
SolutionLet's take your first example: 29/03/4976 to 15/10/5346 (dd/mm/yyyy format).
DATEDIF calculates the number of days as follows:
Why did you get a different result? Because 4976 is a leap year. This causes the difference between 01/01/4976 and 29/03/4976 to be 1 day more. But you don't want to count from 01/01, but from 29/03. (Since 5346 is not a leap year, you don't count an extra day there)
So I would say that DATEDIF is correct here.
May 05 2021 02:44 AM
May 05 2021 02:37 AM
SolutionLet's take your first example: 29/03/4976 to 15/10/5346 (dd/mm/yyyy format).
DATEDIF calculates the number of days as follows:
Why did you get a different result? Because 4976 is a leap year. This causes the difference between 01/01/4976 and 29/03/4976 to be 1 day more. But you don't want to count from 01/01, but from 29/03. (Since 5346 is not a leap year, you don't count an extra day there)
So I would say that DATEDIF is correct here.