I am trying to take a string'd date value from an element, and convert it to a js var in order to use SPServices to add to a SP 2010 list (date field).
I found the date.js resource, but I am not sure how to properly use it. Everything I do that manipulates the date changes it to a string... .format() whatever.
I think I need someway to change the value into : 2013-01-01T19:20:15 in order to pass through SPServices and update the list like below:
function CreateNewItem(subject, message) {
$().SPServices({
operation: "UpdateListItems",
async: false,
batchCmd: "New",
listName: "Example",
valuepairs: [["Title", subject], ["Message", message], ["DateField", date]],
completefunc: function(xData, Status) {
alert("completed");
}
});}
So I tried the Date.parse and it doesn't like the returned value, but I am not sure how to change the returned value without making it a string?
Appreciate help as always.
EDIT: more clarification....I am using XSLT to Grab values from XML file, and creating html page for viewing the values. So with xml
<div id="thisDateExample"><xsl:value of select="thisDateExampleDate"/></div>
So then I have been trying a couple things, like getting the string value from jquery selector:
var thisDateThatIsDrivingMeCrazy = $('#thisDateExample').text();
So again, I am just learning all these things but I am thinking that made it a string, and I found the date.js to get it back to a date format I guess?
var thisDateConverted = new Date(Date.parse(thisDateThatIsDrivingMeCrazy));
Then trying to pass into SPServices? This is one approach that I guess thought made sense, but I must be doing something wrong here? If I alert this is uses a different format from what I need I believe. but again per above, anything I do to format it (or what I can find on the subject to try out) seems to change it to a string (I am assuming) and doesn't work. help is always appreciated! Greatly!
figured this out, though I think with my original question I just lacked some content. I needed to get the date formatted to ISO 8601 format for SharePoint to except it. So all I really needed was something I found here :
function convertThisDate(thisDate){
var myDate;
if (thisDate!= null) {
myDate = thisDate;
}
else {
myDate = new Date();
}
var stringDate = "";
stringDate += thisDate.getYear() + "-";
stringDate += thisDate.getMonth() + 1 + "-";
stringDate += thisDate.getDate();
stringDate += "T" + thisDate.getHours() + ":";
stringDate += thisDate.getMinutes() + ":";
stringDate += thisDate.getSeconds() + "Z";
return stringDate;
}
something as simple as the above works perfect, as SharePoint seems to be very picky about the date.