web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
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
    Microsoft Employee 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 98 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 72

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans