Calculating Months difference between two dates

    The script below calculates the months difference between two given dates. 

     

    //Function to calculate Months Difference in script

    SET MonthDiff = Num(((year($2) * 12) + month($2)) - (((year($1) * 12) + month($1))) + 1);

     

    Now, we can use the MonthDiff as a function

     

    Data:

    LOAD

        UniqueNo,   

        StartDate,

        EndDate, 

        ($(MonthDiff(StartDate, EndDate)) AS MonthsDifference

    FROM DataSource;

     

    In the above load statement we are calculating the months difference between two dates and arriving it as a new column.

     

    We can also use the MonthDiff in expressions also like below

     

    =$(MonthDiff(Today(), Today() + 65))

     

    Hope this helps others.

     

    Regards,

    Jagan.