InfoPath - CAML Date Time format in when submitting to a SharePoint list via a Web Service - SharePoint Development & Administration + InfoPath

Monday, July 27, 2009

InfoPath - CAML Date Time format in when submitting to a SharePoint list via a Web Service

I noticed that when trying to update a SharePoint list item using a CAML query from an InfoPath form, if the date/time format was not correct the field in the SharePoint list item would not be updated. Any updates in the CAML query after an element with an invalid date/time format were also not applied.

The Date Time format in a CAML query must comply with the ISO 8601 standard. This means that to update the time component of a Date/Time field in a SHarePoint list, the time and date must be formatted according to the ISO 8601 profile.

To ensure the time component of the dat/time filed is updated in SharePoint, use one of the the following date/time formats:




Key Components:
  • The date must be in YYYY-MM-DD format
  • "T" indicates the start of the time
  • the time must be in "hh:mm", or "hh:mm:ss" formats
  • The time must be preceded by the time zone offset or a "Z" to indicate UTC (Coordinated Universal Time) the time zone offset must be in "+hh:mm" or "-hh:mm" formats

See W3C's Date and Time Formats for full details about the ISO8601 standard.

The following JScript function converts the date value from an InfoPath form field/control into an ISO 8601 date format for updating the time component of a date/time field in a SharePoint list using CAML:

//Convert the date value passed as a parameter
//into ISO 8601 standard.
//Pass NULL as the date parameter to return the
//current date and time in ISO 8601 format
function getDateTime(date)
if (date != null)
//Date value supplied
d = date;
//No date supplied, Create new date object
d = new Date();

//Generate ISO 8601 date/time formatted string
var s = "";

s += d.getYear() + "-";
s += d.getMonth() + 1 + "-";
s += d.getDate();
s += "T" + d.getHours() + ":";
s += d.getMinutes() + ":";

//Replace the "Z" below with the required
//time zone offset (eg "+10:00" - Australian EST)
s += d.getSeconds() + "Z";

//Return the ISO8601 date string
return s;

Replace the "Z" with the required time zone offset, or leave if UTC is ok.

Related Articles:

Share this article:
Stumble This Delicious
submit to reddit

No comments:

Post a Comment