PHP PDO -在不更新原始行的情况下将表中的时间更改为Unix


PHP PDO - Change time in a table to Unix without updating the original row

我有一个PDO表,其中包含一个名为'creation_time'的列。这是在创建新行时自动创建的,并且具有以下布局—2014-05-09 18:21:18

我有大约20张唱片。我在一个特定的查询,我想转换时间'creation_time' unix在PHP没有实际更新的行。

这是我一直尝试到现在。$today value已经在Unix中

$stmt = $dbh->prepare("SELECT * FROM $table WHERE strtotime(create_date) > :today  ORDER BY id DESC");
$stmt->bindValue(':today', $today, PDO::PARAM_STR);
$stmt->execute();
while ($result = $stmt->fetch()) {
//Display values
//Display values
//Display values
}

我怎么能得到unix时间create_date不更新的值,请?我知道我可以用unix时间创建另一行,但我想避免这个选项

str_to_time()是一个PHP函数,所以你不能在SQL中使用它。你需要使用MySQL的UNIX_TIMESTAMP():

 SELECT * FROM $table WHERE UNIX_TIMESTAMP(create_date) > :today  ORDER BY id DESC

我想在一个特定的查询,我想转换时间'creation_time'到unix

你不需要它。

将日期列与没有unix时间戳的日期值进行比较