The date returned by date picker is off by one day. Is it a problem in my code or is it a bug?
The date sent to date_picker is 2012-03-21. The date returned by dat
I don't know why this works but what I've found is whether you use forward slashes or dashes affects the answer. Take a look.
new Date ('2012/03/21'); // returns: "Wed Mar 21 2012 00:00:00 GMT-0500 (CDT)"
new Date ('2012-03-21'); // returns: "Tue Mar 20 2012 19:00:00 GMT-0500 (CDT)" WHA!
So to fix my issue I did a simple regex on my input date to always replace the first three dashes with forward slashes.
var strInputValue = control.value, // <-- get my date string
dteCurrent;
strInputValue = strInputValue.replace(/-/, '/') // replace 1st "-" with "/"
.replace(/-/, '/'); // replace 2nd "-" with "/"
dteCurrent = new Date(strInputValue);
I did a very quick google search for why this would happen and no answer. But this should fix your issue. All you have to do is replace the dashes with forward slashes before you pass them to where you want them.
Edit: sorry I didn't notice the already accepted answer before posting, please disregard this answer.