gpt4 book ai didi

mysql - 在时间戳内获取记录但不特定于日期

转载 作者:可可西里 更新时间:2023-11-01 07:58:10 26 4
gpt4 key购买 nike

我想获取在晚上 11:02 到 4:04 之间登录的用户的记录,日期无关紧要。

我试过类似的东西:

User.where("TIME(created_at) BETWEEN '11:02:00' AND '04:04:00'")

但它不起作用。非常感谢对此的任何帮助。

最佳答案

函数之间的 mysql 工作方式与您预期的不同。

The between function expect the first parameter to be the min value en the second parameter to be the max value. See the documentation: http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_between

试试这个:

User.where("(TIME(created_at) BETWEEN '23:00:00' AND '23:59:59' OR TIME(created_at) BETWEEN '00:00:00' AND '03:59:59')")

根据您的更新,它将是这样的:

User.where("(TIME(created_at) BETWEEN '23:02:00' AND '23:59:59' OR TIME(created_at) BETWEEN '00:00:00' AND '04:03:59')")

关于mysql - 在时间戳内获取记录但不特定于日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40129581/

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