web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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?

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    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 .

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

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

  • Martin Dráb Profile Picture
    239,022 Most Valuable Professional on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 123

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans