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

Get Month | Day | Year from a Date field in CRM using JavaScript.

(0) ShareShare
ReportReport
Posted on by 70

 Hi All

I’m bit new to JScript, trying to calculate year, month and date from DOB field, I picked up the link from below, and tried it, could any one suggest if this is correct as I’m experiencing error

community.dynamics.com/.../get-month-day-year-from-a-date-field-in-crm-using-javascript

osplitDateandTime = {
    splitDateofBirth : function(exeecutionContext){
    //debugger;
    var formcontext = executionContext.getFormcontext();
    if(formcontext.getAttribute("new_dateofbirth")){
    var datefieldValue = formcontext.getAttribute('new_dateofbirth').getValue();

    if(dateFieldValue !==null){
    var yearDOB = dateFieldValue.getFullYear().toString();
    var monthDOB = (datefieldValue.getMonth()+ 1).toString();
    var dayDOB = dateFieldValue.getDate().toString();

    FormContext.getAttribute("dcuk_year").setValue("yearDOB");
    FormContext.getAttribute("dcuk_monthdob").setValue(("0"+ monthDOB).slice(-2));
    FormContext.getAttribute("dcuk_datedob").setValue(("0"+ dayDOB).slice(-2));

    } else {

        FormContext.getAttribute("dcuk_year").setValue(null);
        FormContext.getAttribute("dcuk_year").setValue(null);
        FormContext.getAttribute("dcuk_year").setValue(null);
    
    }
    }
    }
};

Thanks

Jag

I have the same question (0)

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 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#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