Skip to main content

Notifications

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

  • Verified answer
    MehrCrm Profile Picture
    290 on at
    RE: Different date and time from the database

    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.

  • KaeL Profile Picture
    224 on at
    RE: Different date and time from the database

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

  • Suggested answer
    PranavShroti Profile Picture
    4,510 on at
    RE: Different date and time from the database

    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

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,996 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans