Datedif returning incorrect result

sharshra

Active Member
Joined
Mar 20, 2013
Messages
276
Office Version
  1. 365
I'm using Datedif to calculate number of months between 2 dates. Can anyone advise how to fix this please?

Consider the following example -
H29 - 20-Jul-22
J29 - 19-Sep-22
Datedif -
Excel Formula:
=IFERROR(DATEDIF(H29,J29,"m"),"")

This returns 1 instead of 2.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
1 is correct.
T202210a.xlsm
HIJ
2920-07-2219-09-221
3020-07-2220-09-222
31
4d
Cell Formulas
RangeFormula
J29:J30J29=DATEDIF(H29,I29,"m")
 
Upvote 0
Thanks for the quick reply, Dave. In the following examples, I expect the difference to be returned as follows:
Rich (BB code):
     20th Jul to 19th Sep - 2 months
     20th Jul to 20th Sep - 2 months, 1 day

If Datedif don't return these values, is there any other alternative to get these?
 
Upvote 0
You will have to explain the logic that you want to use.
What is a complete month?
 
Upvote 0
It's normal calculation for the month - One day prior to the current date in the next month. I think example makes it clear.

Example:
First date - 20th Jul 2022; second date - 19th Aug 2022; 1 month. Datedif shows it as 0 month, which is incorrect.

I'm sure there could be ways to calculate using multiple functions. For example, calculate number of days & divide by 30.
Excel Formula:
=(DATEDIF(P3,Q3,"d"))/30

But is there a better way? Is there any built in function that does this?
 
Upvote 0
Thanks, Bebo. I'm already using this. It still returns the month in integers. Wanted to know if there is a better way to get the months in fractions. For example, 1.25 months or 2.6 months.
 
Upvote 0
How about:

Code:
=DATEDIF(P3,Q3+1,"m") + DATEDIF(P3,Q3+1,"md")/30
 
Upvote 0
Solution
FYI - just be aware "md" may give errors - according to microsoft

Known issues​

The "MD" argument may result in a negative number, a zero, or an inaccurate result. If you are trying to calculate the remaining days after the last completed month, here is a workaround:
 
Upvote 0
Thanks, Bebo. I was using this combination of formulas to arrive at the expected result. But wanted to know if there is any function which can do this without having to combine different functions. Anyway, the combination works :) Marking it as solution.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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