Reputation: 61
There is 2 dates column one is from date and second is to date .. and i want to get month difference from these two dates
like if
from date to date month difference
01-02-2019 02-02-2020 13
here 02 (feb) month 2019 till 02 (feb) moth 2020 so this means total 13 months covered..
i tried this but this shows wrong results
month(from date) - month(to date)
and i also try this
month([from date] - [to date])
Upvotes: 1
Views: 607
Reputation: 5012
I've been using the code below for this case.
It basically converts both dates to months and returns the difference.
First the Year
component of the date is "converted" to months (year([to date]) * 12
part) and second adds the month number of the date (month([to date]
)
Num (
( (year([to date]) * 12) + month([to date]) )
- ( ((year([from date]) * 12) + month([from date])) ) + 1
)
UPDATE:
below is a screenshot of the result table with 2 expressions - including the +1
and excluding it. Depends how you want to calculate the full months +1
will "include" the last month as well
Upvotes: 1