SharePoint DateTime incorrect hour?


Hello everyone,

Today I’ll talk about a problem that I had when I wanted to compare dates.

The problem I had was that the time displayed was different from the time that I was recovering through my code! 2h difference to be exact.

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

I met the problem on a 2010 environment but in my opinion it should be the same in 2007 and 2013.

Hope this helps!


This entry was posted in SharePoint 2007, SharePoint 2010, SharePoint 2013 and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s