How do you insert data into a MySQL date or time column using PHP mysqli and bind_param?
I used the date( ) function and this solved me the problem.
$stmt = $mysqli->prepare("INSERT INTO FOO (dateColumn) VALUES ?");
// 6/10/2015 10:30:00
$datetime = date("Y-m-d H:i:s", mktime(10, 30, 0, 6, 10, 2015));
$stmt->bind_param("s", $datetime);
$stmt->execute();
My answer may be slightly off-topic. I had a problem in bind_param when passing date. The date was in (mm/dd/yyyy hh:mm:ss)
format. MySQL was not taking it in (yyyy/mm/dd)
format (which is the default format of date type in MySQL) in bind_param.
The following date formatting solved the problem:
date('Y/m/d', strtotime($date_variable))