将带有日期和时间的php字符串转换为sql时间戳

将带有日期和时间的php字符串转换为sql时间戳,php,postgresql,Php,Postgresql,我有一个php字符串,其中包含日期和时间,如下所示 2015-05-27 18:45:31 如何将其转换为可以插入带有时间戳数据类型的postgresql表中的类型?使用以下函数将其转换: $unix_timestamp=strtotime('2015-05-27 18:45:31'); 在SQL查询中使用$unix\u时间戳 您还可以在SQL语句中使用时间戳'2015-05-27 18:45:31'符号。如果您有其他格式的日期,可以使用DateTime::createFromFormat

我有一个php字符串,其中包含日期和时间,如下所示

2015-05-27 18:45:31
如何将其转换为可以插入带有时间戳数据类型的postgresql表中的类型?

使用以下函数将其转换:

$unix_timestamp=strtotime('2015-05-27 18:45:31');
在SQL查询中使用
$unix\u时间戳


您还可以在SQL语句中使用时间戳'2015-05-27 18:45:31'符号。

如果您有其他格式的日期,可以使用DateTime::createFromFormat

就你而言:

$dateString = '2015-05-27 18:45:31';
$format = 'Y-m-d H:i:s';
$dateConvert = DateTime::createFromFormat($format, $dateString);
echo "Date: $format; " . $dateConvert->format('Y-m-d H:i:s') . "\n";
输出类似于:

Date: Y-m-d H:i:s; 2015-05-27 18:45:31