Geeks With Blogs
The Trials and Tribulations of a Self-Taught Developer By Justin Russell

Here is an annoying inconsistency within the SharePoint Object Model. In list items, you can easily retrieve the Created Date and Modified Date through the OM. It's also pretty easy to get the created date and time for different versions of a list item. What threw me off was that the Created Date and Modified Date of the current item are stored in the time zone set in the SharePoint Administration Web Site (ex: GMT -7) however; the date and times for previous versions are stored in GMT. I was stuck on this probably for longer than I should have been but it's still a maddening irregularity. Anyway; here is how I dealt with the problem...


foreach (SPListItemVersion currentVersion in listItem.Versions)
        versionDateString = currentVersion.Created.ToString();
        versionDate = DateTime.Parse(versionDateString);
        versionDate = versionDate.AddHours(-7);

Posted on Tuesday, July 22, 2008 4:45 PM | Back to top

Comments on this post: SPListItemVersion.Created

# re: SPListItemVersion.Created
Requesting Gravatar...
I think

versionDate = Convert.ToDateTime(currentVersion["created"]).ToLocalTime();

should do better what you want.

Left by Lennin Arriola on Oct 14, 2008 2:51 AM

# re: SPListItemVersion.Created
Requesting Gravatar...
Try using <YourDateTimeObject>.ToLocalTime() instead of -7 hours.
Left by Loganathan.P.C on May 10, 2011 12:48 AM

Your comment:
 (will show your gravatar)

Copyright © Justin Russell | Powered by: