web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    236,907 Most Valuable Professional on at
    RE: How to filter date in where condition?

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

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    RE: How to filter date in where condition?

    Try this,

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

  • junior AX Profile Picture
    1,552 on at
    RE: How to filter date in where condition?

    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
    RE: How to filter date in where condition?

    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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

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

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 588

#3
Martin Dráb Profile Picture

Martin Dráb 542 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans