简体   繁体   中英

How to compare two dates in MS Dynamics AX 2009?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM