Number of months between two dates

How can I get the number of months between two dates?

For example, the number of months between 20/12/2010 and 20/12/2011 is 12. 

Thanks for your help.

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Hi Fabian,

    So AFAIK, i don't think there's a direct way to do this. But using a little logic it's pretty simple. Firstly use the fn!year() on both dates and compare the years difference, if the difference is zero you can proceed with using fn!month function on both dates and get the difference between the two months. If the year difference wasn't zero then u can add those many numbers of months to the above result. So if the year diffference was 1, you add 12 months and so on.

Reply
  • +1
    Certified Lead Developer

    Hi Fabian,

    So AFAIK, i don't think there's a direct way to do this. But using a little logic it's pretty simple. Firstly use the fn!year() on both dates and compare the years difference, if the difference is zero you can proceed with using fn!month function on both dates and get the difference between the two months. If the year difference wasn't zero then u can add those many numbers of months to the above result. So if the year diffference was 1, you add 12 months and so on.

Children
No Data