Friday, August 28, 2015

Date and time functions in AX 2012

today() ————————————>The today function returns the system date,This function does not support time zones.
getSystemDateTime() —————>Gets the current UTC time as a utcdatetime type.
systemDateGet () ———————->The systemDateGet method uses the system date in Microsoft Dynamics AX.
  • Use DateTimeUtil::getSystemDateTime instead of systemDateGet or today. The today function uses the date of the machine. The systemDateGet method uses the system date in Microsoft Dynamics AX. Only DateTimeUtil::getSystemDateTime compensates for the time zone of the user.
  • Avoid using date2str for performing date conversions.
currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(), DateTimeUtil::getUserPreferredTimeZone());
Job
date d;
str time1=”0.50″;
TimeOfDay time;
time = str2time(time1); ———————————————————> convert the String to Date
info(strFmt(“%1″,dayName(dayOfMth(today())))); ———————-> Name of the day in String
print dateMthFwd(systemdateget(),5);  ————————————>  forward to the 5 months
print dateMthFwd(systemdateget(),-5); ————————————> Backward to the 5 Months
 pause;
 Date to String Conversion
info(date2str(today(),123,2,2,2,2,4));
info(date2str(systemDateGet(),123,2,2,2,2,4));
info(date2str(DateTimeUtil::date(DateTimeUtil::getSystemDateTime()),123,2,2,2,2,4));
Get the time in milliseconds
str  milliSecondsAlive = int2str(winApi::getTickCount()); ——————–> Time in MilliSec
str  timeStr;
timeStr = strFmt(“%1 %2”, time2str(timeNow(), 3, 1), substr(milliSecondsAlive, strlen(milliSecondsAlive)-2, 2));
Date And Time Stuff
    str time1=”0.50″;
    TimeOfDay time;
    time = str2time(time1);
    info(strFmt(“%1”,time));                                                                   //convert time ToDate string
    info(strFmt(“%1”,dayName(dayOfMth(today()))));           // Name of the Day in String

No comments:

Post a Comment