简体   繁体   English

MySql选择今天的所有内容

[英]MySql select all for todays day

I have a select query that is: 我有一个选择查询:

SELECT id FROM entries 
WHERE email_address = ? 
AND created_date >= DATE_SUB(NOW(), INTERVAL 1 DAY) 
LIMIT 1 

and it works. 它的工作原理。 But I want to change my created_date >= ... to be the last day rather than day + time. 但我想将我的created_date >= ...更改为最后一天而不是一天+时间。 Is this possible? 这可能吗?

So right now a user cannot enter more than once in a 24 hour period. 所以现在用户不能在24小时内输入多次。 I want to change it to be a day, so a user could enter at 11:59PM once on a day and then 12:01am immediately the following day. 我希望将其更改为一天,因此用户可以在晚上11:59 PM进入一天,然后在第二天立即进入12:01。

How can I change my select to account for this? 如何更改我的选择以解决此问题?

The easiest way is to convert created_date from a datetime to just a date. 最简单的方法是将created_date从日期时间转换为日期。

DATE(created_date) >= DATE_SUB(CURDATE(), INTERVAL 1 DAY)

BUT watch out for timezones! 但要注意时区! And doing this will mean the index on created_date is not used, so make sure that doesn't hurt things. 这样做意味着不会使用created_date上的索引,所以请确保不会伤害事情。

NOW()更改为CURDATE() ,这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM