Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to pass lesser than created date range in query class

(0) ShareShare
ReportReport
Posted on by 242

Hi,

I want to pass a 'CreatedDateTime' range value to a query in runtime to delete a table records which has the 'CreatedDateTime' value lesser than the parameter value that is been passed as query range value.

When the parameter value is been fetched, it is in the correct format of '9/27/2017 11:30:44 am'. But when I pass the same to query range using the below syntax, it is getting converted to the format '2017-09-27T15:31:48' which is not making the query to select the records properly.

utcDateTime         createdDateTime;

createdDateTime= dataContract.parmFromDate(); //This returns utcDateTime value - 9/27/2017 11:30:44 am

 

queryBuildrange = query.dataSourceTable(tableNum(TestTable)).addRange(fieldNum(TestTable, CreatedDateTime));
queryBuildrange.value(strFmt('<%1', createdDateTime)); //This adds the range value as 2017-09-27T15:31:48

Any suggestions pls!

Thanks!

 

*This post is locked for comments

  • Suggested answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: How to pass lesser than created date range in query class

    You should use SysQuery::range() for setting the value. The lower bound would be utcDateTimeNull() or DateTimeUtil::maxValue() depending whether you want left or right open bounds for your date range (possibly null is the right one in your case).

    [View:https://msdn.microsoft.com/en-us/library/sysquery.range.aspx:750:50]

    Also make sure that you do not forget to set timezone offset for the UTCDateTime values if applicable.

  • Chaitanya Golla Profile Picture
    Chaitanya Golla 17,225 on at
    RE: How to pass lesser than created date range in query class

    Hi,

    Please try the following:

    queryBuildrange.value(strFmt('<%1', queryValue(createdDateTime))); (or)
    queryBuildrange.value(strFmt('(CreatedDateTime < %1)', DateTimeUtil::toStr(createdDateTime)));

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,432 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans