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

Transform DateTime field to Date javascript

(0) ShareShare
ReportReport
Posted on by 115

Im using this code to retrieve an entity with a datetime field. When i retrieve the field i get it in this format  "Date(16456222000000)" as string, how can i transform that to a date that i can compare?


function retrieveRecord(recordId) { var clientURL = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest(); var query = "/api/data/v8.2/entitySetName?$filter= idlogicalname eq " + recordId; req.open("GET", encodeURI(clientURL + query), true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json;charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { var data = JSON.parse(this.response); } else { var error = JSON.parse(this.response).error; alert("Error retrieving Record – " + error.message); } } }; req.send(); }
I have the same question (0)
  • Esteban Coto Alfaro Profile Picture
    on at

    Hello, if the format of the string when you retrieve it is always the same "Date(xxxxx)", what I recomend is to get the number from the string and create a new Date type var and you pass to it the number that you get from the string, for example:

    var str = "Date(16456222000000)";

    var num = str.replace(/\D+/g, ""); // console.log(num) if you want to check the value

    var date = Date(num);

    console.log(date);

    Thanks!

    Community Support Team - Esteban

    If this Post helps, then please consider Accept as solution to help the other members find it more quickly.

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

#2
Gerardo Rentería García Profile Picture

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

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans