Monsieur Winner

MS D365FO || Monsieur D365FO

Technical

Number of days between two Date fields in D365FO (X++)

There are several scenarios where one would want to know the date difference between two dates.

  • Getting an investment tenor where user inputs investment startDate and maturidtyDate.
  • Getting the number of leave days when the employee picks a startDate and an endDate.
  • Number of days spent by an employee on probation.

We can do a simple subtraction : this.endDate – this.startDate.

We can also make use of the intvNo built in function. You can get the day, month and year difference between two dates.

    public static void main(Args _args)
    {
        date fromDate = str2Date("02/18/2018", 213);
        date toDate = str2Date("08/20/2022", 213);
     
        // Days
        info(strFmt("Day(s): %1", intvNo(toDate, fromDate, intvScale::YearMonthDay)));
        // Months
        info(strFmt("Month(s): %1", intvNo(toDate, fromDate, intvScale::YearMonth)));
        // Years
        info(strFmt("Year(s): %1", intvNo(toDate, fromDate, intvScale::Year)));
    }

Number of days between two Date fields in D365FO (X++)

admin

Komi Siabi is a Bilingual D365FO Solution architect who loves sharing his knowledge as he works on Both Francophone and Anglophone projects around the globe. He enjoys doing some tiktok videos in his leisure time.

0 thoughts on “Number of days between two Date fields in D365FO (X++)

  • Your comment is awaiting moderation.

    Thanks for your help and for writing this post. It’s been great.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *