how to convert a date/time value received by "json decoding"
2018-01-05T22:58:23.937 (value of $TimeStamp)
to insert into a SQL-Database-Field type of DATETIME
$query = "INSERT INTO database (date1,...) VALUES ($ddate1, ...)
this won't work:
$ddate1 = date_format(new datetime($TimeStamp), 'y.m.d H:i:s');
removing 'T' won't work either
$ddate1 = strtr($TimeStamp,"T"," ");
$ddate1 = date_format(new datetime($ddate1), 'y.m.d H:i:s');
UPDATE 6.01.2018
$now = date("y.m.d H:i:s"); $TimeStamp = $fgc['result'][$i]["TimeStamp"]; // (result of json)
echo "OK:" .$now .'<br />';
echo "nOK: (format of source) sorce" .$TimeStamp .'<br />';
$dt1 = date('Y.m.d H:i:s', strtotime($Timestamp)); echo "convert:" .$dt1 .'<br />';
$dt2 = date('Y-m-d', strtotime($Timestamp)); echo "convert:" .$dt2 .'<br />';
Result:
OK:
18.01.06 12:48:39
(sample stored correcrtly in database)
nOK: (format of source) sorce2018-01-06T11:48:40.207
convert:1970.01.01 01:00:00
convert:1970-01-01
thanks for any hints
Stefan