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 :
Microsoft Dynamics CRM (Archived)

Read Date Value from Dynamics CRM

(0) ShareShare
ReportReport
Posted on by 25

Hello,

I need to read Date value of one DateTime field in my Dynamics CRM Form using JavaScript.

I am able to read the value but it is not exactly same what I can see in CRM.

In CRM Form, selected value is: 17th May 2018
JavaScript Code return value as: Wed May 16 2018 00:00:00 GMT+0530 (India Standard Time)


CRM logged in user time-zone: GMT +10:00 Sydney

My time-zone: +5:30 India

JavaScript Code I am using is:

var dateFieldValue= Xrm.Page.getAttribute('MyDateField').getValue();
var year = dateFieldValue.getFullYear();
var month = dateFieldValue.getMonth();
var day = dateFieldValue.getDate();
new Date(year,month,day);

May I know how can I get exact date using JavaScript which I am selecting in DateTime control?

Thanks,
Mohit

*This post is locked for comments

I have the same question (0)
  • Beat Bucher  GP Geek  GPUG All Star Profile Picture
    28,058 Moderator on at

    Hi Mohit,

    I moved this question to a new thread under the CRM group, since it nothing to do with the original question (which was SSRS related).

    Regards,

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    Hi Mohit,

    Please try below code for getting the Date in correct format,

    var dateFieldValue= Xrm.Page.getAttribute('MyDateField').getValue();

           date = dateFieldValue.getDate(),

           month = "January,February,March,April,May,June,July,August,September,October,November,December"

         .split(",")[dateFieldValue.getMonth()];

       function nth(d) {

         if(d>3 && d<21) return 'th'; // thanks kennebec

         switch (d % 10) {

               case 1:  return "st";

               case 2:  return "nd";

               case 3:  return "rd";

               default: return "th";

           }

       }

       var result = date+nth(date) +" "

       +month+" "+dateFieldValue.getFullYear();

    If you find it helpful, please mark my answer as verified.

    Best Regards,

    Shahbaaz

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Mohit,

    You could also look for the date time field behaviors and if it suiots your business then you can change the format to "Date" only.. This will ensure that the date will be returned without any timezome conversion.

    docs.microsoft.com/.../behavior-format-date-time-field

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Mohit ,

    Try with this - 

            var dateFieldValue = Xrm.Page.getAttribute('MyDateField').getValue();
            var dateFieldValue = new Date(dateFieldValue);
            var year = dateFieldValue.getFullYear();
            var month = (dateFieldValue.getMonth() + 1);
            var day = dateFieldValue.getDate();
            var ExactDate = day + "/" + month + "/" + year;


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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans