I'm trying to insert a time written in h:mm am/pm format into a database that is stored as standard DATETIME format ( hh:mm:ss ) but I can't figure out how to convert the posted time into standard format so the database will accept it.
This is what I've been trying so far:
$title = $_POST['inputTitle'];
$date = $_POST['inputDate'];
$time = date('h:i:s a', strtotime($_POST['inputTime']));
$desc = $_POST['inputDesc'];
//msql query to insert data
$query = "INSERT INTO events(title, date, time, description) VALUES ('$title','$date','$time','$desc')";
but this doesn't work(time still won't submit) any ideas?
You should use TIME type not DATETIME type.
DATETIME format is: yyyy-mm-dd hh:ii:ss
DATETIME format
TIME format is: hh:ii:ss
TIME format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With