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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to filter date in where condition?

(0) ShareShare
ReportReport
Posted on by 1,552

Hi,

If i want to say in the where condition the following:

Select table1 where table 1 is less than today's date by 2 months

How can i do that? Because each month might have different number of days

Or i shall do today's date - 30 and that's it?

What's the syntax?

I have the same question (0)
  • Martin Dráb Profile Picture
    237,697 Most Valuable Professional on at

    I would utilize DateTimeUtil::addMonths(x, -2).

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Try this,

    DateTimeUtil::date (DateTimeUtil::addMonths (DateTimeUtil::newDateTime (asOfDate, 0), -2));

  • junior AX Profile Picture
    1,552 on at

    Hi Martin,

    Is this correct? And would it give me what i'm looking for?

    Table.CreatedDateTime < DateTimeUtil::AddMonths(DateTimeUtil:: getToday(DateTimeUtil::getUserPreferredTimeZone()),-2);

    Hi Baharani,

    I'm not sure why you used newDateTime and what is asOfDate?

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Asofdate is the date which is like to provide in range like some date minus 2 months and it will the exact date value as a range. Here asofdate is simply a variable where you should give the date from where you want to go back to 2 months.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans