So as the title says, I keep losing a day as I go from mysql to my javascript and I cant figure it out. You lose a day when you insert into the data base (let’s say I put 10/14/12 the database will read 10/13/12) and I also lose a day when I read from the database (I fetch the 10/13/12 and it now reads 10/12/12).
Here is my process:
//date input from jquery ui datepicker
$('#datepicker'+p).datepicker({numberOfMonths: 3, showButtonPanel: true, dateFormat: "D, d M, yy"});
//date sent to php to upload to mysql so there is a format conversion
$start = date("Y-m-d", strtotime($startdate));
Now on to downloading:
//date taken from mysql no modifications
//date modified to be sent to viewer in a nicer format
var start = $.datepicker.formatDate('D, d M, yy', new Date (item.start));
What I think: the issue seems to happen both ways and I am pretty sure my javascript is not the issue and because there is only php conversion one way that seems to rule out both. Could this be an issue with my mysql server? ALSO NOTE that the dates are saved in mysql as type DATE!
//as requested my sql code
INSERT INTO classdates (start, end, hours, days, off, notes, type, branch) VALUES(:start, :end, :hours, :days, :off, :notes, :type, :branch)
I figured out my issue was the javascript
new Date() function. It is not just converting the date but also manipulating it. I had to accommodate for the timezone change.