作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想获取在晚上 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/
我是一名优秀的程序员,十分优秀!