Sunday, November 1, 2020

How to get Date or Time from UTCDateTime in ax 2012 using X+

 

Hi guys, Today we see how to get date or Time from UTCDateTime in ax 2012 using X++. 


Run the below job.


static void dateFunctions(Args _args)

{

    CustTable       custable;

    int             daysdiff;

    Date            _Currentdate;

    utcDateTime     _UtcStartPeriod;

    utcDateTime     _UtcEndPeriod;

    utcDateTime     dateTime;

    date            dateInUserTimeZone;

    TimeOfDay       timeInUserTimeZone;

    AccountNum      _accountNum = '456';

    

    select custable where custable.AccountNum == _accountNum;

    

    // Convert normal date into utcDateTime

    _currentdate=today();

   _UtcStartPeriod =  DateTimeUtil::newDateTime(_currentdate,0);


    // Convert utcDateTime into Date

    dateInUserTimeZone = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(custable.modifiedDateTime, DateTimeUtil::getUserPreferredTimeZone()));

    timeInUserTimeZone = DateTimeUtil::time(DateTimeUtil::applyTimeZoneOffset(custable.modifiedDateTime, DateTimeUtil::getUserPreferredTimeZone()));

    //dateTime = DateTimeUtil::newDateTime(dateInUserTimeZone, timeInUserTimeZone, DateTimeUtil::getUserPreferredTimeZone());

    

    daysDiff =  dateInUserTimeZone - today();


    info(strfmt("today date - %1",today()));

    info(strfmt("cust account date - %1",dateInUserTimeZone));

    info(strfmt("cust account time - %1",timeInUserTimeZone));


    info(strfmt("days difference - %1",daysDiff));

}

Output:





Keep Daxing!!

No comments:

Post a Comment