Conversion: Date to utcDateTime
Refer to Date to UTCDateTime Convertion Dynamics Ax 2012
Sometimes we might need to query the data on field 'createdDateTime' whose type is utcDateTime so this code will help to convert type Date to utcDateTime.
Value 0 to 86400 stand for the time period 00:00:00 to 23:59:59
date exampleDate = 01\02\2015; // it's 01-Feb-2015
utcDateTime utcStartDate,
utcEndDate;
CustTable custTable;
;
utcStartDate = DateTimeUtil::newDateTime(startDate,0);
utcEndDate = DateTimeUtil::newDateTime(endDate,86400);
select count(RecId)
from custTable
where custTable.createdDateTime >= utcStartDate &&
custTable.createdDateTime <= utcEndDate;
-------------------------------------------------------------------------------------------------------------
utcDateTime: how to increase or decrease datetime value
Sometimes we might need to query the data on the specific range. This below would help to get idea to increase or decrease utcDateTime.
utcDateTime currentday,
yesterday;
;
currentday = DateTimeUtil::utcNow();
yesterday = DateTimeUtil::addDays(currentday, -1);
yesterday = DateTimeUtil::addSeconds(yesterday, 1);
info(strFmt('%1',currentday));
info(strFmt('%1',yesterday));
-------------------------------------------------------------------------------------------------------------
Conversion: numeric to Time (TimeOfDay)
we can convert numeric (0 - 86400) to TimeOfDay by following code.
TimeOfDay aaa;
;
aaa = 3600;
info(time2Str(aaa, TimeSeparator::Colon, TimeFormat::AMPM));
aaa = 4200;
info(time2Str(aaa, TimeSeparator::Colon, TimeFormat::AMPM));
aaa = 10800;
info(time2Str(aaa, TimeSeparator::Colon, TimeFormat::AMPM));
No comments:
Post a Comment