web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

AX 2012 How to use a date range in a query ?

(0) ShareShare
ReportReport
Posted on by

Hi everybody,

I am trying to query a table with a range based on a Date type field but the query does not find my record. I tried it with another type (Int64) and it is working.

I tried it with another table (TSTimeSheet) with a range based on a Date field(PeriodFrom) and it is not working neiher.

Do we have to make a specila manipulation when we are working with Date Type in a Query ?

Here is my complete Code.

static void Test1(Args _args)
{
    Query q = new Query();
    QueryRun qr;
    QueryBuildDataSource qbds;
    lmb_EmplTimeBankTable lmb_EmplTimeBankTable;
    Fromdate tmpFromDate = 1\1\2011;
    //HcmWorkerRecId   workerId = 5637144672; 

    ;

    qbds = q.addDataSource(tableNum(lmb_EmplTimeBankTable));
    //qbds.addRange(fieldNum(lmb_EmplTimeBankTable, YearFromDate)).value(queryvalue(tmpFromDate));
    qbds.addRange(fieldNum(lmb_EmplTimeBankTable, worker)).value(queryvalue(WorkerId));

    qr = new QueryRun(q);

    while(qr.next())
    {
        lmb_EmplTimeBankTable = qr.get(tableNum(lmb_EmplTimeBankTable));
        info(strfmt("Account Num: %1, Name: %2", lmb_EmplTimeBankTable.Worker, tmpFromDate));
    }

}

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Use this if you want to add a date query range:

    qbds.addRange(fieldNum(CustTable, CreatedDateTime)).value(date2StrUsr(tmpCreatedDate));

    Kind regards.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans