How to compare two dates in MS Dynamics AX 2009?
Asked Answered
L

1

5

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?

Linger answered 11/8, 2011 at 18:22 Comment(2)
"from the table"? Compare 2 dates in the same table or in two different tables. If needed copy your query to the question.Lydgate
If you find an answer useful, please accept the answer.Lydgate
L
7

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.

Lydgate answered 12/8, 2011 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.