[null, {"document_url": "http://www.malindesilva.net/2016/01/sharepoint-datetime-field-rest-api-time.html", "unformatted_src": "https://2.bp.blogspot.com/-acxx_1OOd0s/Vcw42MxBs1I/AAAAAAAAAgM/VJOyg10asn8/s320/TimeZone.PNG", "src": "https://2.bp.blogspot.com/-acxx_1OOd0s/Vcw42MxBs1I/AAAAAAAAAgM/VJOyg10asn8/s320/TimeZone.PNG", "formatted_filename": "TimeZone", "rendered_width": 320, "rendered_height": 250}, null, null, null, null]

SharePoint DateTime field REST API Time Zone Issue

We all think this is an issue, but it is not. REST API for SharePoint has its own way of handling things compared to the other APIs. There are a few things we need make note.

1. SharePoint stores date in 0000 UTC timezone.
2. We have a different regional setting (timezone) for the SharePoint site. For the example, let me set the time zone as (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi.

So once I save a datetime value or a date value as 2015-08-13 in that particular SharePoint site. It will be stored as 2015-08-12 18:30:00 as it is the equivalent UTC time.

<d:Created m:type="Edm.DateTime">2015-08-12T18:30:00Z</d:Created>

Now if you retrieve that record through the REST API, it will show the date time value as 2015-08-12T18:30:00Z. As you can see in this value, Z represents timezone and there is no value in front of that after the hour:minute:seconds value.

Now when you are using this value, it needs to be translated to the timezone where the user's browser is setup with. Then we can give the accurate date time value for the necessary time zone.

Another scenario is storing only the date value. We assume then only the date value will be stored, but it is not the case with SharePoint. It stores the Date and Time value. So it will still show a day less than the actual if you do not consider the timezone.
Posted by Malin De Silva at 12:00 PM Labels: SharePoint Development, SharePoint Server 2013, SharePoint Server 2016


