How to compare two dates (instances of type Date, not utcDateTime) in MS Dynamics AX 2009?
I want to check if particular date, taken from the table, is before (or after) the another one. Both are date types.
Is there a way to convert date to utcDateTime datatype?
How to compare two dates?
Use the comparison operators <
<=
>=
>
==
and !=
.
if (LedgerTrans.TransDate > systemDateGet() - 3)
LedgerTrans.TransDate = systemDateGet() - 3;
This works in selects too:
select firstonly LedgerTrans
where LedgerTrans.TransDate > systemDateGet() - 3;
It works in query input ranges as well: >13-08
will select select dates after August 13'th of the current year.
See also: http://kashperuk.blogspot.com/2010/02/utcdatetime-in-dynamics-ax-2009.html
How to convert a date to utcDateTime
?
DateTimeUtil::newDateTime(systemDateGet(), 0, DateTimeUtil::getUserPreferredTimeZone()));
See also: http://msdn.microsoft.com/en-us/library/cc584924.aspx
There is no need to convert Date
to utcDateTime
to compare two dates.