I\'m trying to use javascript to convert a date object into a valid mysql date - what is the best way to do this?
Can be!
function Date_toYMD(d)
{
var year, month, day;
year = String(d.getFullYear());
month = String(d.getMonth() + 1);
if (month.length == 1) {
month = "0" + month;
}
day = String(d.getDate());
if (day.length == 1) {
day = "0" + day;
}
return year + "-" + month + "-" + day;
}
Take a look at this handy library for all your date formatting needs: http://blog.stevenlevithan.com/archives/date-time-format