gpt4 book ai didi

mysql - 如何使用 Mysql 过滤时间戳格式?

转载 作者:行者123 更新时间:2023-11-29 05:27:26 25 4
gpt4 key购买 nike

我只想问一下如何在Mysql中过滤时间戳值?

假设我们有以下日期时间

1351128031

1351128045

1351128097

如何使用这种格式创建日期范围?如何在查询中执行此操作?

像这样:

SELECT * FROM user
WHERE acct_created BETWEEN (datefrom) AND (dateto) -- my problem is I can't filter the timestamp

最佳答案

您想使用名为 UNIX_TIMESTAMP 的 mysql 函数 http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp

SELECT * FROM user
WHERE acct_created BETWEEN UNIX_TIMESTAMP('datefrom') AND UNIX_TIMESTAMP('dateto')

其中 datefrom 和 dateto 是格式化为字符串的日期,类似于 UTC 中的“2012-01-01 00:00:00”

关于mysql - 如何使用 Mysql 过滤时间戳格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18480209/

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