UpdateListItem Date Format?

Jul 18, 2012 at 7:33 PM

I am trying to update a record in a list...no problem.  However, the column I need to update is a date field. 

What format is the date expected to be?  Is it a "date" or a string? 

Thanks,

Don

Jul 18, 2012 at 8:09 PM

See the thread at http://spservices.codeplex.com/discussions/349356. Down a bit within that one is a comment that includes a note about formatting dates to the ISO 8601 format to be compatible with SharePoint and includes a sample function for doing so.


Jul 18, 2012 at 8:13 PM

Remember, the XML you are sending in is only an XML representation.  Under the hood in JS, it's simply a string.  Here's a function that will format the date correctly for your web service call:

 

var isoDate = function( d ) {
	//defaults to new date
	d = d || new Date();

	function pad( n ) {
		return n < 10 ? '0' + n : n;
	}

	return d.getUTCFullYear() + '-' +
		pad( d.getUTCMonth() +1 ) + '-' +
		pad( d.getUTCDate() ) + 'T' +
		pad( d.getUTCHours() ) +':' +
		pad( d.getUTCMinutes() )+':' +
		pad( d.getUTCSeconds() )+'Z'
	;
};

Usage example:

var now = isoDate(); // typeof(now) === string is true

var then = isoDate( someDateVariable ); // typeof(then) === string is true

 

Cheers,
Matt 

Jul 18, 2012 at 8:29 PM

Thanks, guys.  Reformatting the date into a string of that format did the trick.  I found elsewhere the same thing with the time zone added.  So I used it that way... "YYYY-MM-DDT00:00:00-6:00" 

Don

May 8, 2014 at 11:38 AM
I used moment.js to reformat the date into ISO format

http://momentjs.com/docs/#/displaying/as-iso-string/
Coordinator
May 8, 2014 at 12:28 PM
I added a function in SPServices 2013.02 to assist with this called $().SPServices.SPConvertDateToISO, in case it's helpful. But moment.js rocks for doing anything with dates and times.

M.