Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Fetch exactly 6 month older record from current date

Posted on by 524

Hi,

I am having a date field in a custom entity. I need to fetch exactly the 6 months older record by comparing that date field with the current date. How can I build the fetchxml ?

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Fetch exactly 6 month older record from current date

    Hi,

    Where do you want use this logic ?

    In plugin, if yes then change operator to ON instead of on or before and pass the value as

    AddMonth(DateTime.now(),-6).ToShprtDateString();

  • Anandhcrm Profile Picture
    Anandhcrm 524 on at
    RE: Fetch exactly 6 month older record from current date

    no.. I need like this..

    for example, if I'm having the records in my entity like this..

    name,  joineddate

    aaa,    12/04/2022

    bbb,   13/04/2022

    ccc,    14/04/2022

    ddd,   13/04/2022

    my fetchxml will give the records having the date exactly 6 months old of joined date

    the result should be if the current date is 13/10/2022 are:

    bbb, 13/04/2022

    ddd, 13/04/2022

    result should be if the current date is 14/10/2022 are:

    ccc, 14/04/2022

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Fetch exactly 6 month older record from current date

    Hi,

    You need to select below condition in your fetchXml.

    On or before - set value dynamically in your c# code by using below code

    AddMonths(your custom field date value, -6)

  • Suggested answer
    Ray Profile Picture
    Ray 1,505 on at
    RE: Fetch exactly 6 month older record from current date

    Hi,

    Another way is to use the "olderthan-x-months" operator,

    <condition attribute="<AttributeName>" operator="olderthan-x-months" value="6" />

    Here is the doc

  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Super User 2024 Season 1 on at
    RE: Fetch exactly 6 month older record from current date

    Hi Anandhcrm,

    You can resolve your problem by using the On or Before clause.

    pastedimage1665497615837v1.png

    If I answer your question then please mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform & Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans