Question

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

Was it helpful?

Solution 2

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

OTHER TIPS

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.

myDate.toJSON();
//"2014-03-07T14:48:56.431Z"

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">
    <label>Date:</label>
    <input type="text" value="03/14/2014" id="effectiveDate" />
    <p>
    This is not JSON format:
        <div id="notJson"></div>
    </p>
    <p>
     This is JSON format:
     <div id="isJson"></div>
    </p>
    <p>
     Object in JSON:
        <div id="myObject"></div>
    </p>
</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() });
    $("#myObject").text(myObject);    
  });

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top