there is 2 dates from date and to date .. and i want to get month difference from these two dates
from date to date month difference 01-02-2019 02-02-2020 13
i tried this but this shows wrong results
month(from date) - month(to date)
and i also try this
month([from date] - [to date])
See if this works for you:
year(from date) * 12 + month(from date) - year(to date) * 12 - month(to date)
The logic is simple here - you're creating the date 2019-02-01 to months as well as 2020-02-02.
2019-02-01 becomes 24230
2020-02-02 becomes 24242
The difference between them is 24242-24230=12 months.
I guess this is what you expect to get, isn't it?
When i tried your expression .. i have one of the record like this
from date to date difference
and this is showing difference like -84,007 .. how is that possible ?
but i have some records like these
|From date||to date||Difference|
and these show differences 0 which is incorrect..
A little script to show you how I might tackle this.
This takes into account days, so
2018-03-01 - 2018-01-20 would return 1 (complete month)