This project has moved and is read-only. For the latest updates, please go here.

UpdateListItem Date Format?

Jul 18, 2012 at 8:33 PM

I am trying to update a record in a 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? 



Jul 18, 2012 at 9:09 PM

See the thread at 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 9: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



Jul 18, 2012 at 9: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" 


May 8, 2014 at 12:38 PM
I used moment.js to reformat the date into ISO format
May 8, 2014 at 1: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.