Reputation: 187
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?
Upvotes: 3
Views: 2242
Reputation: 159
You should use TIME
type not DATETIME
type.
DATETIME
format is: yyyy-mm-dd hh:ii:ss
TIME
format is: hh:ii:ss
Upvotes: 4