How to compare two dates in MS Dynamics AX 2009?

How to compare two dates (instances of type Date rather than utcDateTime) in MS Dynamics AX 2009?

I want to check if a particular date taken from a table is before (or after) another. Both are date types.

Is there a way to convert date to datatype utcDateTime?

+4
source share
1 answer

How to compare two dates?

Use the comparison operators <= >= > == and != .

 if (LedgerTrans.TransDate > systemDateGet() - 3) LedgerTrans.TransDate = systemDateGet() - 3; 

This also works when choosing:

 select firstonly LedgerTrans where LedgerTrans.TransDate > systemDateGet() - 3; 

It also works in the query input ranges: >13-08 will select the selection dates after August 13 of the current year. See Also: http://kashperuk.blogspot.com/2010/02/utcdatetime-in-dynamics-ax-2009.html

How to convert 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.

+6
source

All Articles