Thursday, January 28, 2016

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.  

1 comment:

  1. Hi,

    I am facing same issue. My browser locale is india and I have added value in list as 8/1/2016 both India and US users see the same date but while fetching it through CSOM and displaying is on page is shows diffent value for different user.
    How do I fetch the exact value which is displayed in List Item.

    ReplyDelete