Possible Duplicate:
php/Mysql query with inserting date fails
I have a datepicker code below:
$(function() {
$( "#datepicker" ).datepicker({minDate: 0,
dateFormat: "dd-mm-yy"
});
});
As you can see the format of the date when it is displayed in the datepicker textbox (‘dateChosen’) is ‘dd-mm-yy’ which is like this (20-05-2012).
But when I try and insert the date in the ‘SessionDate’ field, instead of displaying ‘2012-05-20’ in the database, it keeps displaying ‘0000-00-00’. Why is it doing this?
What I want is the textbox format to remain the same but when the date is inserted into the SessionDate table, then I want it inserted as ‘2012-05-20’ and not as ‘0000-00-00’.
Below is code for the insert ($_POST[‘dateChosen’] is the post method which posts the date):
$sql="INSERT INTO Session (SessionDate)
VALUES
(' ". mysql_real_escape_string( $_POST['dateChosen'] ) . "'
)";
mysql_query($sql);
Your dateformat is
dd-mm-yy, so the date will be of the type:31-03-12and not31-03-2012. MySQL can’t accept that value in its dateformat syntax. Try this in insert query: