gpt4 book ai didi

php - 如何将 Firebird 数据库 TIMESTAMP 与 PHP time() 值进行比较?

转载 作者:行者123 更新时间:2023-12-04 04:56:31 24 4
gpt4 key购买 nike

我的数据库有一个 TIMESTAMP 类型的数据字段。它被称为“我的时间”。我从 php 的 time() 函数中得到一个数字。例如:

print time();

然后我查询数据库:
SELECT * FROM mytable where mytime > 1369157557

它提示:
conversion error from string "1369157557"

我猜您无法将 PHP 时间戳与 Firebird 时间戳进行比较。为什么不呢?我该如何解决?

最佳答案

有两个选项:在比较之前将该 unix 时间戳转换为 Firebird 时间戳。或者做一些类似 this message on the Firebird-Support list 中描述的事情:

select DATEDIFF(second, timestamp '1/1/1970 00:00:00', current_timestamp)
from rdb$database
或者特别是在您的查询中:
SELECT * 
FROM mytable
where DATEDIFF(second, timestamp '1/1/1970 00:00:00', mytime) > 1369157557
请记住,存储在数据库中的时间可能不会以 UTC 存储,在这种情况下,您还需要考虑与 UTC 的偏移量。

关于php - 如何将 Firebird 数据库 TIMESTAMP 与 PHP time() 值进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16687296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com