问题
What is the best way to convert a utcDateTime value to a date type so I can use the global datetime functions on it?
int timeDiff;
date _now = systemdateget();
;
select firstOnly myUTCDateTime from _myTable
timeDiff = Global::yearDiff(_now, _myTable.myUTCDateTime);
info(strfmt('%1', timeDiff);
Thanks
回答1:
The DateTimeUtil Class has methods for dealing with utcdatetime variables. In your case you would use DateTimeUtil::date
.
timeDiff = Global::yearDiff(_now, DateTimeUtil::date(_myTable.myUTCDateTime));
回答2:
Logic for utcdatetime :
utcdateTime testDonedateTime1;
utcdateTime testDonedateTime;
transdate tmpDate ;
timeofday tmpTime;
testDonedateTime1 = inventJournalTable.PostedDateTime;
testDonedateTime = DateTimeUtil::applyTimeZoneOffset(testDonedateTime1, DateTimeUtil::getUserPreferredTimeZone())
tmpDate = DateTimeUtil::date(testDonedateTime);
tmpTime = DateTimeUtil::time(testDonedateTime);
Important : utcDateTime control properties TimeZonePreference set No conversion
回答3:
utcDateTime _dateTime = 2012-12-31T13:59:58;
date _date;
;
_date = DateTimeUtil::date(_dateTime);
info(strFmt('%1',_date));
来源:https://stackoverflow.com/questions/1972600/axapta-convert-utcdatetime-to-date