Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

JavaScript to display number of days based upon selected date and today's date

(0) ShareShare
ReportReport
Posted on by 62

I have a field named "OI Date" where user can select the date. Also I have a dropdown field called "Opportunity age group" where the option set will be 0-30 days, 31-60 days and so on.

My requirement is to display the "Opportunity age group" option sets automatically by comparing how old the opportunity is based on "OI Date" and the date when the record is created (Today's date). 

For eg:

If the OI date is 13.08.22 and I am entering the record today then the option set should display as 0-30 days by comparing OI date and the date record is created on.

Can anyone help me how to write script for this?

  • Martin Dráb Profile Picture
    Martin Dráb 231,409 Most Valuable Professional on at
    RE: JavaScript to display number of days based upon selected date and today's date

    Abdul (and all other users), please report spam if you run into it. See Microsoft Dynamics Community Help > Reporting Abuse.

    You can also contact moderators of the given forum or - as suggested in the link - forum administrators. (I'm not a moderator of CRM forum; I just found this post when looking for spam.)

    Mentioning @Admin or @Support in your reply has no effect.

  • Abdul Wahab Profile Picture
    Abdul Wahab 12,081 Moderator on at
    RE: JavaScript to display number of days based upon selected date and today's date

    Hi Xavier Wyman,

     

    Please do not use this forum for your marketing. @Admin or @Support please take notice.

    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/.../

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: JavaScript to display number of days based upon selected date and today's date

    Hi,

    You can write below javascript code to find number of days between two dates

    Var date1=new Date("06/30/2019");

    Var date2=new Date("07/30/2019");

    Var diff_in_time= date2.getTime()-date1.getTime();

    Var diff_in_days= diff_in_time/(1000*3600*24);

    Now use diff_in_days variable in If condition to set the optionset field .

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,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans