0

What format does Project Online save dates? In the ProjectData api, I can see all of the date fields saved as /Date(1612944000000)/ . Using the /_api/web for the actual project subsites, you see that LastModifiedDate etc. are saved in the normal UTC format.

Why is this?

2 Answers 2

1

That's probably the raw milliseconds.

Dates are actually stored as numbers that represent ticks of a certain size from a certain starting point.

From the MDN documentation on JavaScript dates:

A JavaScript date is fundamentally specified as the number of milliseconds that have elapsed since midnight on January 1, 1970, UTC.

And it then goes on to point out the difference between JavaScript dates and UNIX time stamps, and that in UNIX the tick is a full second (not millisecond):

This date and time are not the same as the UNIX epoch (the number of seconds that have elapsed since midnight on January 1, 1970, UTC), which is the predominant base value for computer-recorded date and time values.

And, in the C# DateTime struct, the ticks are 100 nanoseconds, and are counted since 12:00 midnight on Jan 1, 0001 AD.

So there are some differences. Why would I assume the ones coming from the Project Online REST API are in milliseconds?

Well, for one, Date(<something>) looks a heck of a lot like the JavaScript Date constructor. And, in addition to using an ISO string ("2021-02-10T08:00:00.000Z") or a short date format string ("2/10/2021"), you can use a number representing milliseconds since Jan 1 1970 in the Date constructor.

Second, I am also assuming that you are sending a header of Accept: application/json along with your REST request, which is telling Project Online that you want your response in JavaScript Object Notation, which is a pretty big clue to Project Online that you are using JavaScript, so it might format a response it's going to send in JSON in a JavaScript-friendly way.

And third, it's Project Online, and a heck of a lot of modern development, especially revolving around using cloud services/APIs, is very client-side oriented, meaning, done in JavaScript. So they could be leaning heavily on that expectation as well.

That's all speculation though. I really am just guessing that it's milliseconds (based on those hunches).

A quick test to see if that's right? Open up a browser console, and just try it out:

// doing this
new Date(1612944000000)

// outputs
Wed Feb 10 2021 03:00:00 GMT-0500 (Eastern Standard Time)

At least, that's what I get in my time zone. Does that date and time make sense for what you are expecting?

As far as why there is a difference between how REST API date results are formatted for the Project Online API vs. the SharePoint API, I guess that's a question for the Microsoft development teams...

(As a side note - I haven't worked with Project Online. I have worked with Project Server 2016 on-prem, and results from the /ProjectData/ REST API in that version do come back as ISO strings, same as from SharePoint, at least if you are looking at things like TaskFinishDate, TaskBaselineFinishDate, etc..)

1
  • Thanks Dylan! You are a wealth of knowledge for Project... I did use the new Date function & then toLocaleString to get what I needed.. but I just wondered why I had to do all the extra work lol. Mar 4, 2021 at 21:54
0

Your WebApi requests gives a hint that you want to have a JSON result as Dylan Cristy explain.

The default JSON serializer of C#/.Net Framework was Json.NET. Until version 4.5 of the library this was the default format of serialized DateTime properties. This now is called known as MicrosoftDateFormat: https://www.newtonsoft.com/json/help/html/datesinjson.htm

Nowadays C#/.Net includes a new JSON serializer. The new serializer and Json.NET itself both has a new resulting date-format: an ISO-8601 string value with second-precission.

Btw.: This change leads to another problem: without a schema nobody knows if this received string should be converted into a JS date or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.