Skip to content

jQuery Date returns wrong values?

I have a date picker that returns it value as Mandag, 03/05/2021 today is 3rd May 2021. Now i passed it to date function

var pickedDate_n = new Date(pickedDate);
console.log(pickedDate_n);

And it returns Fri Mar 05 2021 00:00:00 GMT+0530 (India Standard Time)

var pickedDate_ch = (pickedDate_n.getDate()) + "/" + (pickedDate_n.getMonth()) +  "/" + pickedDate_n.getFullYear();
      console.log(pickedDate_ch);

Now that returns, which is totally wrong

5/2/2021
      

Answer

In javascript date format is "MM/dd/yyyy" could you check the date format. which you are assigned to pickedDate.

use this for change the date format to datepicker:

var date = $('#datepicker').datepicker({ dateFormat: 'MM-dd-yyyy' }).val();