Search code examples
axaptax++dynamics-ax-2009

Greater than date in Axapta 2009 X++


I am looking to write a query that will select all Sales Orders greater than a certain date in X++. This would be part of a job that I am writing.

Something like this:

SalesTable.createdDateTime > '2016-09-01'

I believe that I need to use DateTimeUtil::newDateTime to do it. I've seen examples like:

where salesLine.createdDateTime == DateTimeUtil::newDateTime(systemdateget(), 0)

How do I put an actual date in there? Or should I be using a different method? QueryBuilder perhaps?

Many thanks,

Anna


Solution

  • Using AX's query syntax or using a query object all depends on your use. Doing a date/time is useful for either.

    Here is an example job that shows a more correct way to do what you want and also shows timezone considerations.

    You can build a date object or a utcDateTime, which is more likely what you'll need to do.

    static void DateTimeExample(Args _args)
    {
        utcDateTime         myDateTime;
        date                myDate;
        TimeOfDay           myTimeOfDay;
    
        // Set your date
        myDate          = mkDate(1,10, year(today())); // Ex. October 1, 2016
    
        // Set time of day or just use 0
        myTimeOfDay     = DateTimeUtil::time(DateTimeUtil::utcNow());
    
        // Build your utcObject
        myDateTime  = DateTimeUtil::newDateTime(myDate, myTimeOfDay);
    
        // Apply timezone offset
        myDateTime  = DateTimeUtil::applyTimeZoneOffset(myDateTime, DateTimeUtil::getCompanyTimeZone());
    
        info(strFmt("utcDateTime: %1", myDateTime));
    }