Date Difference in months.

zulqzulq Member Posts: 204
Want to find the difference between two dates and return the corresponding number of months.
For example Let say: Begin Date and End Date and they both have values 01/01/05 and 31/12/05 respectively. Now I want to find the difference but in months only. With the above example the number of months will be 12.
Any ideas please!
Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?

Comments

  • kinekine Member Posts: 12,562
    and difference between:

    31/01/06 and 01/02/06 will be 1 month or 0?
    between 01/01/06 and 28/02/06 will be 1 or 2?

    Please, more details needed. But best thing will be to use DATE2DMY function to take numbers of month and year for each date and calculate the values from this...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • David_CoxDavid_Cox Member Posts: 509
    You could use a variable Calendar > Record > Date
    IF (FromDate <> 0D) and (ToDate > FromDate) THEN BEGIN
        Calendar.RESET; 
        Calendar.SETRANGE("Period Type",Calendar."Period Type"::Month);
        Calendar.SETRANGE("Period Start",FromDate,ToDate);
        Months := Calendar.COUNT;
    END ELSE
         Months := 0;
    

    The problem with this type of code is 01 Jan 07 to 01 Feb 07 will return 2 Months.

    When it is only 1 month 1 day!

    31/01/06 and 01/02/06 will be 1 month
    between 01/01/06 and 28/02/06 will be 2 Months
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
  • zulqzulq Member Posts: 204
    Hello Kine,
    Here the dates are going to be standard...Payments are made monthly...thus the dates will be begin of month to end of month respectively.
    Ok will try these and get back.
    Thanks.
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
  • zulqzulq Member Posts: 204
    Thanks a lot guys...
    Its working perfect.
    Few years ago we were not existing and few years to come we would be in the grave! So what will benefit us in the grave?
Sign In or Register to comment.