在mysql表中插入日期

时间:2016-11-12 16:56:42

标签: php mysql datetime

我正在从API中获取日期并尝试将该日期插入到我的数据库中的表中。但是,无论我尝试什么,它都不能插入任何东西(即错误)或它只是插入00:00:00。

表格中的字段类型为DATETIME。

API JSON中日期的格式如下:

2016-08-28T15:00:00Z

我尝试过转换成各种各样的。我试过以下

$date = 2016-08-28T15:00:00Z;
$date = strtotime($date);
$finalDate = date('Y-m-d h:m:s', $date);

echo $finalDate;
//this echos the date in the format I'd expect to see it in the database - 2016-08-28 15:00:00

但是当我将$ finalDate插入表中时,它会出错。 (带有消息'SQLSTATE [42000]的未捕获异常'PDOException':语法错误或访问冲突:)

有什么想法吗?

0 个答案:

没有答案
相关问题