In this example I will convert UTCDateTime type into Date type date myDate = DatetimeUtil::Date(MyUTCDateTime)
Category: Date functions
AX / D365FO – How to clear a date field in X++
To clear a date just use datenull() method SalesParam.TransDate = datenull();
AX / D365FO – Add minutes to a DateTime field
This simple job shows how to add 5 minutes to the system UTCDateTime static void AddMinutes(Args _args) { utcDateTime dt; dt = DateTimeUtil::getSystemDateTime(); info(strFmt('Before : %1', dt)); dt = DateTimeUtil::addMinutes(dt, 5); info(strFmt('Before : %1', dt)); } This is the result
SQL SERVER – Update a DateTime field
This is an example on how to update a Datetime field including Hour, minutes and seconds update [dbo].[Quote] set modifiedOn = CONVERT(datetime,'2021-11-11T10:22:59.000',126) where quoteid in (80635, 80609)
AX – D365FO – convert datatime to string in a specific format
Custom formatting string in .NET makes it really easy. static void Job61(Args _args) { System.DateTime dateTime = System.DateTime::get_UtcNow(); str utcTimeAsStr = dateTime.ToString('yyyyMdd_HHmmss'); info(strFmt("Datetime in GMT: %1",utcTimeAsStr)); } This code achieves this output Datetime in GMT: 20211105_113052
AX – D365FO – Convert UtcDateTime to string
static void DateTest(Args _args) { UtcDateTime dateTime = DateTimeUtil::getSystemDateTime(); //This gets the curent UTC datetime print DateTimeUtil::toStr(dateTime); //This converts UTC DateTime into String pause; }
AX – D365FO – Get current system DateTime (with hours, minutes, seconds)
You can use DateTimeUtil::getSystemDateTime() method to extract current system DateTime with hours, minutes and seconds. utcDateTime todayDate = DateTimeUtil::getSystemDateTime(); It will return date in this format : 01/11/2021 15:42:23
AX – D365FO – X++ date runtime functions
Here you can find the complete X++ Date runrtime functions : https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/dev-ref/xpp-date-run-time-functions
AX – D365FO – How to get current system Time?
time2str(timenow(),1,1)
AX – D365FO – split datetime in hour minutes second in different timezone
This is the example to split datetime in hour minutes second in different timezone TransDateTime myDateTime=DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(),Timezone::GMTPLUS0300KUWAIT_RIYADH); int hours; int minutes; int seconds; ; info(datetime2str(myDateTime)); hours=DateTimeUtil::hour(myDateTime); minutes=DateTimeUtil::minute(myDateTime); seconds=DateTimeUtil::second(myDateTime); info(strfmt('Hours %1 - Minutes %2 - Seconds %3',int2str(hours),int2str(minutes),int2str(seconds)));