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)

Different date and time from the database

(0) ShareShare
ReportReport
Posted on by 224

Hi guys, i query to get the date and time value of the field_validFrom  and i check on the database, there's two data/record save on the database that is field_validFrom(this is the correct date and time) and field_validFromutc(incorrect one) but the data that i get was the utc datetime or maybe the conversion was wrong? and this is my conversion for the dateandtime

convertODataDateToODataString: function (crmDate) {
var date = new Date(parseInt(crmDate.replace("/Date(", "").replace(")/", ""), 10));
date = date.toISOString();
return date;
},

and this is the datetime save on my database the first one was field_validfrom and the second is field_validfromutc

2045.datetime.PNG

but im sure that the data they get was the utc. Does anyone knows this?

Thanks for the help

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at

    see if you are getting UTC DateTime for CreatedOn, and you can looking to convert to local time:

    var createdOn=Xrm.Page.getAttribute("createdon").getValue();

    var LocalDate=new Date(CreatedOn+ "UTC")

    Local Date will give current Date and Time

    Check some basics here : www.powerobjects.com/.../crm-2011-truths-about-datetime

    If found useful, please mark the answer as verified

    Regards,

    Pranav

  • KaeL Profile Picture
    224 on at

    this time i got invalid date. Thank you so much for the reply.

  • Verified answer
    MehrCrm Profile Picture
    290 on at

    This is caused by the way JavaScript Date object parses date strings. Take a look at this W3C page https://www.w3schools.com/js/js_date_formats.asp

    The following returns (wrong) date (Tue Mar 24 2015 20:00:00 GMT-0400 (Eastern Daylight Time)

    var d = new Date("2015-03-25");

    However the following returns the correct date (Wed Mar 25 2015 08:00:00 GMT-0400 (Eastern Daylight Time)

    var d = new Date("2015-03-25T12:00:00Z");

    As per W3C:

    Omitting T or Z in a date-time string can give different result in different browser.

    UTC (Universal Time Coordinated) is the same as GMT (Greenwich Mean Time).

    The solution that we came up with was to break the date string into it's various parts, year, month, ... and create the date by using the Date constructor rather than relying on the JS Date object string parser. This will always produce the correct date.

    var d = new Date(yyyy,mm - 1,dd,hh,mm,ss);

    Hope this helps.

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