≡ Menu

Date to UTCDateTime Convertion Dynamics Ax 2012

Usually we have to convert date to UTCDateTime. That is usally case when we have to query on createdatetime filed of very table, which filled when new row is created.

We for this purpose we have to create use DateTimeUtil::newDateTime function. This function takes two values one for date, and second for time. So time values will be range beween 0 and 86400. It means when value time is 00:00:00 value will be 0 and when time is 23:59:59 then value will be 86400. Consider following code which creates start and end date for same date.


Date _Currentdate;

utcDateTime _UtcStartPeriod;

utcDateTime _UtcEndPeriod;






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

_UtcEndPeriod = DateTimeUtil::newDateTime(_UtcEndPeriod,86400);


What if we have to convert UCTDateTime to DateTime, We can do it like

_currentdate = DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(_UtcEndPeriod, DateTimeUtil::getUserPreferredTimeZone()));

Comments on this entry are closed.