php - MySQL Timestamp INSERT okay but sometimes fails -
so i've got bootstrap 3
form , there clockpicker
, datepicker
plugins in it. data through php , try insert mysql
(currently in xampp). insert okay, 1 or both of timestamp
fields in db left @ 0000....
since display date 17/09/2016
try save 2016-17-09
in mysql , have concatenate text clockpicker text date picker, that:
$startdate = $_post['shiftstartdate'] . " " . $_post['shiftstarttime']; $startdateformat = str_replace('/', '-', $startdate); $date1 = date_create($startdateformat); $datetime1 = date_format($date1, 'y-d-m h:i:s'); $enddate = $_post['shiftenddate'] . " " . $_post['shiftendtime']; $enddateformat = str_replace('/', '-', $enddate); $date2 = date_create($enddateformat); $datetime2 = date_format($date2, 'y-d-m h:i:s');
any ideas?
solution: when formatting, conform mysql's requirement of y-m-d, not y-d-m:
$datetime2 = date_format($date2, 'y-m-d h:i:s');
mysql expects date format yyyy-mm-dd hh:mm:ss when save database in datetime or timestamp column datatype
you trying save yyyy-dd-mm. work if dd less 12 explains why works , not
so format dates correctly mysql expects , well.
i expect getting odd results when read dates did save database.
Comments
Post a Comment