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, ...
Answered

how to query weekday

(0) ShareShare
ReportReport
Posted on by 577

The following code is to query exact date.

QueryBuildRange qbr = qbs.addRange(fieldNum(SalesTable, ShippingDateRequested)).value(SysQuery::value(today()));

If today is Tuesday, how to search the same weekday eg. last Tuesday, Tuesday two weeks ago, and so on

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: how to query weekday

    Hi Tony,

    I think you can just simply deduct 7 days (or 14, 21...) to get the same weekday.

    The example below is just for illustrative purposes, but you should be able to use this idea to solve your requirement.

    Date dateCriteria = today - 7;
    QueryBuildRange qbr = qbs.addRange(fieldNum(SalesTable, ShippingDateRequested)).value(SysQuery::value(dateCriteria));

  • Tony Mok Profile Picture
    577 on at
    RE: how to query weekday

    Hi Nikolaos Mäenpää,

    As I need to show all same weekday weeks ago not just only one day eg. last Tuesday, the proposed code does not work.

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: how to query weekday

    Hi Tony,

    as I wrote, it's an illustration, not a full solution to your requirement.

    You can add many ranges to get many weekdays.

  • Tony Mok Profile Picture
    577 on at
    RE: how to query weekday

    Hi Nikolaos Mäenpää,

    Your method can be applied for few weekdays but not ALL, it cannot be applied for large date range, eg. 1/1/2000 to 10/26/2021.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: how to query weekday

    I beg to differ on that one. You just need a loop that adds each day range one by one.

  • Tony Mok Profile Picture
    577 on at
    RE: how to query weekday

    The loop is used and it works.

    TransDate dateCriteria = today();
    
    while(dateCriteria > mkDate(1, 1, 2000))
    {
        QueryBuildRange qbr = qbs.addRange(fieldNum(SalesTable, DeliveryDate));
        qbr.value(SysQuery::value(dateCriteria));
        dateCriteria = dateCriteria - 7;
    }

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
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 753

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 534 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans