SharePoint Datetime update is one day off

InfoPath alternatives for form designing SharePoint

This is almost certainly a result of your timezone. When a Date Only picker returns a value, it returns a DateTime, where the time component is midnight for the local timezone – e.g. 2012-01-04 00:00:00.

When this value is converted to UTC time, it can become a value for the previous day. For email, if the local time zone for the above datetime is +2, then UTC time would be 2012-01-03 22:00:00.

Read some SharePoint 2013 tutorials below:

Naturally, if you simply look at the date part of the date time, this now appears to be an entire day before. I would suggest you start by looking at the date component of the Expiry date – is that offset by your timezone setting?

SharePoint does store all datetimes in UTC time, so it will convert that local datetime to UTC. I’m not sure, off the top of my head, what timezone the datetimes in the AfterProperties are in.

The problem I’m updating a list with a date field (just the date) using the Client object model but when the date is inserted is one day off from the introduced date.

After searching for a long time, it turns out that the “problem” was how SharePoint stores dates. Indeed SharePoint converts dates to UTC … that’s why my comparison was not good!

So when you want to work in code behind with dates, do not forget to convert to UTC!

For this, two methods:
SPTimeZone.UTCToLocalTime et SPTimeZone.LocalTimeToUTC

Another option would be to retrieve the time zone of SharePoint and explicitly convert now in local time by using the .NET Framework when you save the item list as shown below.

//1.Retrieve SharePoint TimeZone

var spTimeZone = context.Web.RegionalSettings.TimeZone;

context.Load (spTimeZone);

context.ExecuteQuery ();

//2.Resolve System.TimeZoneInfo from Microsoft.SharePoint.Client.TimeZone

var fixedTimeZoneName = spTimeZone.Description.Replace(“and”, “&”);

var timeZoneInfo = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(tz => tz.DisplayName == fixedTimeZoneName);

//3.Convert Time

listItem [“DateTime”] = TimeZoneInfo.ConvertTimeFromUtc (dt, TimeZoneInfo);

Hopefully this SharePoint tutorial will help you.

Similar SharePoint 2013 Tutorials

About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →

Leave a Reply