I am saving a date picking from date picker of jqueryUI. While saving I am using REST Services. But the problem is that it taking the date one day before. And timezone is changing (already have chacked my site collection's timezone, It set properly ). And also if I add the record OOTB then it working properly. Please suggest what can be the issue. Thanks

  • Could you post your code examples and the output? I'd like to see what you are sending via REST and what is being returned to you after you send the data. – Robert Kaucher Mar 7 '14 at 14:56

Before I can say for sure, I really need to see your code. But make sure that what you are sending via REST is not the toString() output of the date but the toJSON() output.


From your comment I don't think you understand what I am saying. You are sending the object as a JSON string to the API but you are NOT sending the date string in the correct JSON format.

See this JSFiddle. Here is the code of the fiddle

<div class="container">
    <input type="text" value="03/14/2014" id="effectiveDate" />
    This is not JSON format:
        <div id="notJson"></div>
     This is JSON format:
     <div id="isJson"></div>
     Object in JSON:
        <div id="myObject"></div>

$(function() {
    $( "#datepicker" ).datepicker();
    $("#notJson").text($( "#effectiveDate" ).val());
    $("#isJson").text(new Date($( "#effectiveDate" ).val()).toJSON());
    var myObject = JSON.stringify({ "__metadata": { "type": "SP.Data.MYListItem" }, "Title": "DEFAULT", "EffectiveDate": $("#effectiveDate").val() });

Here is what the output looks like. Notice the difference between the JSON format and the non-JSON format of the date?

enter image description here

  • Already I am sending the data by converting in to the JSON format by JSON.stringify(); function of JQuery Follwing is the code for that data: JSON.stringify({ "__metadata": { "type": "SP.Data.MYListItem" }, "Title": "DEFAULT", "EffectiveDate": $("#effectiveDate").val() }) – Prasad Gavande Mar 8 '14 at 5:04
  • What is $("#effectiveDate").val() actually outputting? – Robert Kaucher Mar 8 '14 at 13:32
  • I added some more details. Which version of the REST API are you using SP2013 or are you using ListData.svc? – Robert Kaucher Mar 8 '14 at 15:26

After referring this Link I have clear the Idea what is actual problem And I got the solution. For taking the date with my current Timezone just few changes required to get correct date, It's:

$("#isJson").text(new Date($( "#effectiveDate" ).val()).toDateString()); 

This gives you correct answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.