Today I faced interesting issue: I retrieved list item, saved its modification date to datetime object and and started to iterate through that list item's versions. In first iteration i tried to compare item's modification date and version's creation date (which at first iteration should be equal), but values was different by few hours, it worked out after I converted modified date to UTC, but that's a weak solution. Because all values was gotten from single list item object, their time formats (regional time/timezones) should be equal, so how should I convert and compare these values?
1 Answer
SharePoint stores its datetime fields in UTC time. If you don’t look at the data from SharePoint through the UI (the UI corrects datetime values according to local time), you need to correct the datetime fields with the UTC offset you have locally.
http://itblog.wolthaus.net/2011/09/sharepoint-stores-dates-in-utc-time/ http://sharepointtaproom.com/2012/10/26/caml-query-utc-date-comparisons-in-sharepoint/
-
So basically, it just means that the spItem["Modified"] shows server time while spItemVersion.Created shows universal time. So I can freely convert modification date to UTC, without fearing mismatch on different server or if item is updated from different timezone?– ViliusSep 25, 2014 at 7:22
-
You should always compare the dates in UTC. And also test it one or two server for testing. So there wont be any fear of mismatch.– AanchalSep 25, 2014 at 8:08
-
yes, but if I, for example, write spItemVersion.Created.ToUniversalTime() - my time zone region is UTC+2 and spItemVersion.Created already shows UTC time, so after ToUniversalTime() fucntion it just subtracts 2 hours from time which is already UTC– ViliusSep 25, 2014 at 8:30
-
1Dont change the time which is already in UTC. The time which you are getting in your time zone. COnvert that only to UTC. Like your modification date. Change only that– AanchalSep 25, 2014 at 8:34