Possible Duplicate:
convert date string to mysql datetime field
I have a DateTime column in MySQL database. I would like to convert Form text field data on POST (string) to DateTime before inserting into the database. I appreciate any suggestions.
Possible Duplicate:
convert date string to mysql datetime field
I have a DateTime column in MySQL database. I would like to convert Form text field data on POST (string) to DateTime before inserting into the database. I appreciate any suggestions.
It depends on format of MySQL date time field and the format of the form field. Normally db datetime is Year-Month-day Hour:min:sec for example, "2011-10-24 14:25:20". Now to convert form submitted date string to datetime, do the following:
$date = strtotime($_POST['form_date']);
$DatabaseDate = date("Y-m-d H:i:s", $date);
Now you can use the above $DatabaseDate to insert datetime into database:
@mysq_query("INSERT INTO TEST_TABLE (id, date_test) VALUES (2, '$DatabaseDate')");
Hope it helps.