3

What is the best way to save date object in SPO list with JSOM? because date where is saved is not correct

This is my code(experiments)

//This is my date string where i get from datepiker - **25/01/2017** --> $("#holidayDateFromValue").val()

var dtTest = new Date(moment($("#holidayDateFromValue").val(), 'DD.MM.YYYY'));

var dt = new Date(dtTest.getFullYear(), dtTest.getMonth(), dtTest.getDay());

But date where is saved in list is: 03/01/2017

Where i'm wrong?

1
  • Please add proper question if you find any solution to your question is large.
    – Pradip R.
    Jan 25, 2017 at 10:24

1 Answer 1

7

The problem is that you are using the method getDay(). That method will give you the day of the week in this case 3. You should be using the method getDate().

var dt = new Date(dtTest.getFullYear(), dtTest.getMonth(), dtTest.getDate());

-Hope it helps.

1
  • I'll try, moment :)
    – Goshky
    Jan 25, 2017 at 12:42

Your Answer

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

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