GetVersionCollection with DateTime colum returns value one day off!

Aug 16, 2012 at 1:27 PM

Hi, 

I am using the GetVersionCollection webservice to query the version history of a list column of type 'date and time'. And the returned histroical values are one day shy. For example, historical values of 16/08/2012 and 20/08/2012 will return values of 15/08/2012 and 19/08/2012

 

The SP web interface for "version history" of the list shows the correct values, but the value returned using SPServices and GetVersionCollection is one date shy.

 

Here is the code - simple enough:

 

 $().SPServices({
		operation: "GetVersionCollection",
		async: false,				 		 
		strlistID: "testlists",
		strlistItemID: 1,
		strFieldName: "datestamp",
		completefunc: function (xData, Status) {
		 	$(xData.responseXML).find("Version").each(function() {
				alert($(this).attr("datestamp"));
			});				
		}
 });

The date alerted is one day less than it should be!

 

Mike

Aug 16, 2012 at 1:53 PM

I tested this on both Moss2007 and Sharepoint 2010 - and get the same result, the date time value is returned 1 day less than the real value.

Aug 16, 2012 at 3:58 PM

I have not looked at that closely but would suggest you consider the time zone you're in relative to GMT and how the SharePoint server's regional settings are configured as well as your local machine.  SharePoint is storing date/time values in the ISO 8601 standard as GMT.  For instance, I'm in the US Eastern Time zone which is currently GMT minus 4 hours.  If my version says 7/24/2012 1:57 PM on my site page, SharePoint would return that as 2012-07-24T17:57:23Z in the XML. That is the actual GMT of the version and indicated as 4 hours later than displayed in my version history.  The regional settings are making the adjustment on my display to show me local time.  So, if your regional settings aren't correct, you may be getting some crazy returns.

Coordinator
Aug 17, 2012 at 3:15 AM

And keep in mind that SPServices is simply faciliatating your call to GetVersionCollection. SPServices helps by building up the SOAP envelope and such, but the results coming back are simply what SharePoint is giving you.

M.

Aug 20, 2012 at 2:46 PM
Edited Aug 20, 2012 at 2:50 PM

Hi, 

Thanks for your replies.

Mark - yes, I realize that SPServices is simply returning the value from the webservice - but I thought this would be the best place for the discussion. 

The timezone in the regional settings on all servers I tested this on was BST. I also tested this on my clients dev server - again seems to be BST - and had the same issue.

I tracked this down to a problem in rounding the date. You see the date value in the column was provided by a date control, with "00:00:00" concatenated onto the ending in JS, as the updatelistitems service appeared to require a time portion to the date stamp.

Now the GetVersionCollection service was rounding this time differently, depending on whether the date was in the past, or the future. A stored value of :

01/01/2012 00:00:00 (in the past) would be returned by the getversioncollection as 01/01/2012

A stored value of 18/10/2012 00:00:00 (in the future) would be returned as 19/10/2012 - one extra day in the future.

To fix this, I simply concatinate a less dubious timestamp onto the value I send to updatelistitems: 18/10/2012 05:00:00.

This avoids the rounding issue, and my problem - but doesn't really explain the bug in the webservice.

Mike

 

 

 

 

 

Coordinator
Sep 6, 2012 at 3:14 PM

Interesting, Mike. If Microsoft was still interested in the SOAP Web Services (they are officially deprecated in 2013, but I know people will continue to use them), I'd consider filing a bug. However, I doubt they would do anything with it.

M.

Aug 18, 2014 at 7:35 AM
Edited Aug 18, 2014 at 7:42 AM
Hi,

I'm using GetVersionCollection Spservices to get version history of list item, time differs from the last modified and the time i get from version using GetVersionCollection
i'm using spservices 0.7.1 min.js
Time i get from GetVersionCollection is 5:30 hours behind my time zone. If anyone knows please help!!


Thank you.

Maha
Coordinator
Aug 18, 2014 at 3:33 PM
Maha:

The timestamps you are getting are undoubtedly in UTC. You will need to do the conversion. I use Moment.js for this sort of thing.

Also, I would definitely recommend upgrading to SPServices 2014.01. You're way behind.

M.