web
You’re offline. This is a read only version of the page.
close
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?

I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,983 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
    237,817 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 144 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans