2

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!

7
  • where are you declaring/setting date? Commented Jan 11, 2013 at 17:12
  • @Shmiddty ..added more information to post in edit. thanks Commented Jan 11, 2013 at 17:25
  • And what is the value of #thisDateExample? Commented Jan 11, 2013 at 17:27
  • @Shmiddty...Tue Jan 1 19:20:15 EST 2013 is what I get if I use Date.parse...2013-01-01T19:20:15 is the value on the page that comes from the xsl Commented Jan 11, 2013 at 17:31
  • So your question is unclear... You're trying to change "2013-01-01T19:20:15" into "2013-01-01T19:20:15"? (no change) Commented Jan 11, 2013 at 17:34

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.