MySql database excludes A.M, P.M, from datetime, timestamp, time, PHP, SQL -
i have 3 data types in database. datetime, timestamp, , time. time using date function , tried insert database under 3 columns, 3 columns rejected a.m, p.m part of date function. don't understand why. need a.m, p.m part of date function inserted, can sort data in database more efficiently time. there column can store a.m, p.m part of date, or there workaround this? thanks.
$time = date('h:i:s a'); //insert $time 3 columns database
the workaround use hours
value 24 hour clock. represent '3:45:56 pm
', insert database column string value '15:45:56'
.
otherwise, can use str_to_date
function convert string valid time
value.
insert mytable (mycol) values (str_to_date('3:45:56 pm','%h:%i:%s %p'))
to retrieve time
value database column, formatted 12 hour clock am/pm.
select date_format(mytimecol,'%h:%i:%s %p') mytimestr ...
references:
Comments
Post a Comment