Tuesday, February 9, 2010

Conversion of UTCDateTime in Dynamics AX 2009

Recently I have faced a problem of conversion from UTCDateTime variable. I searched everywhere blogs, msdn & finally got result.I am really thankfull for www.axaptapedia.com/UtcDateTime blog for the refference. This job is indicating converting from UTCDateTime to seperate variables as well as seperate variables to UTCDateTime variable.

public static void RAJ_UTCDateTimeConversion()
UTCDateTime dateTime;
date tmpDate;
TimeOfDay tmpTime;
CustTable cTable = CustTable::find("1101");

// Extracted date & Time from UTCDateTime datatype to individulal variable
dateTime = cTable.createdDateTime;

tmpDate = DateTimeUtil::date(dateTime);
tmpTime = DateTimeUtil::time(DateTimeUtil::applyTimeZoneOffset(dateTime, DateTimeUtil::getUserPreferredTimeZone()));

info(strfmt("Date: %1 and Time: %2.", tmpDate, time2str(tmpTime,1,2)));

// assign UTCDateTime varriable by using two individual field
dateTime = DateTimeUtil::newDateTime(12\05\2010, timeNow());
info(strfmt("UTCDateTime: %1.",dateTime));

No comments: