Search code examples
excelexcel-formuladate-difference

Why is the Excel DateDif function returning 0 months for dates between "4/30/2020" and "3/31/2020"?


Microsoft says the DateDif function: =DATEDIF(A3,B3,"M") returns the full number of months between those two dates assuming A3 = Starting month and B3 = Ending month.

However, for dates between 4/30/2020 and 3/31/2020, I am getting a value of 0. I was expecting to get a value of 1. DateDif between 3/1/2020 and 5/31/2020 returns 2, while datedif between 4/30/2020 and 5/31/2020 returns 1 - both of which makes sense to me. So why is the DATEDIF between 4/30/2020 and 3/31/2020 returning 0?


Solution

  • one can create their own version and use vba's DateDiff:

    Function MyDateDif(srt As Date, ed As Date, str As String) As Long
        MyDateDif = DateDiff(str, srt, ed)
    End Function
    

    Then you would use it:

    =MyDateDif(A3,B3,"M")
    

    Which returns 1 as it should

    enter image description here