Problem with UpdateListsItems

May 6, 2011 at 2:44 AM

Hi, I'm trying to update a datetime fields, but I have a problem with the sharepoint datetime format.

Is correct use this format YYYY-mm-ddTHH:mm:ssZ ?

Regards,

Coordinator
May 9, 2011 at 1:04 AM

I just tested this in my environment to be sure of my answer. This worked:

  $().SPServices({
    operation: "UpdateListItems",
    async: false,
    debug:true,
    listName: "Sales Opportunities",
    ID: 5,
    valuepairs: [["Lead_x0020_Date", "2011-05-08 12:12:12"]],
    completefunc: function (xData, Status) {
    alert(xData.responseXML.xml);                }
  });

I believe that the date/time you use must be based on the current locale settings rather than UTC.

M.

Sep 10, 2011 at 2:50 AM
Edited Sep 10, 2011 at 2:50 AM

How do you format your Lead Date column so that it can be passed into the Value Pairs?  I have a date time field and when I do

var dateVal= $("[title$='Date']").val(); 
alert(dateVal);

I get 9/9/2011.  What/how can I pass that through jQuery to get 2011-09-09 00:00:00 (column is a date only field) so that I can pass it into the value pairs and thus insert an item?

Sep 10, 2011 at 6:06 AM

@PirateEric

If you can guarantee your data being the same each time you use:

var dateVal= $("[title$='Date']").val();

Then you can use .split() on your variable.  This will create an array of whatever your delimiter is.  In your case it's the "/". So an example would be:

function PrefixZero(v) {
 return ( v.length == 1 ? "0" + v : v );
}

var arrDate = dateVal.split("/");

arrDate[2] + "-" + PrefixZero(arrDate[1]) + "-" + PrefixZero(arrDate[0])

That will get your year-month-day in the correct format, but it relies on the variable dateVal to be in a certain format.  There are libraries to handle date parsing (date.js), which are much more accurate at handling any date inconsistencies that may crop up. Also, you don't have to worry about passing in a time value unless that's important to you...

Hope this all works b/c I didn't test it, but post back if needed. :D

Cheers,

Matt

 

Sep 11, 2011 at 12:15 AM

Well the date is coming from a date picker so it should always be in that format.  I'll check over the code and date.js, should get me pointed in the right direction.

Coordinator
Sep 11, 2011 at 7:01 PM
Eric:

As messy as Matt's answer may seem, it's the right one. When you have a single locale setting, hard wiring this stuff seems perfectly OK to me. Dates are simply a PITA on any programming language.

If you don't use date.js, what I usually do is build a file called utilities.js or something where I put all of these reusable utility functions. Then I just reference it when I need it.

M.
>
Sep 13, 2011 at 12:52 PM

I was able to get it sorted out.  Fortunately I don't have to worry about  multiple locales, thank goodness.  It is a valid concern to note for others stumbling across the thread.