web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

X++ code to deduct days from date time field in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post we will see how to deduct a day from given date time field and for demo purpose used static methods of class DateTimeUtilClass.

Note: CG_DeductDaysFromDateTime is a runnable class.

public static void main(Args _args)
    {   
        utcdatetime dateTime;
        date        datePart;
        TimeOfDay   timePart;
        int         monthPart;
 
        dateTime = DateTimeUtil::getSystemDateTime();
 
        // Deducts one day from current day
        datePart = DateTimeUtil::date(dateTime) - 1;
        timePart = DateTimeUtil::time(dateTime);
        dateTime = DateTimeUtil::newDateTime(datePart, timePart);
        info(strFmt("New date time is %1", dateTime));
 
        dateTime = DateTimeUtil::getSystemDateTime();
        dateTime = DateTimeUtil::addDays(dateTime , -1);
        info(strFmt("New date time is %1", dateTime));
    }
Regards,
Chaitanya Golla

Comments

*This post is locked for comments