I'm trying to run a mysql select statement where it looks at today's date and only returns results that signed up on that current day. I've currently tried the following, but it doesn't seem to work.
我尝试运行一个mysql select语句,它查看今天的日期,并且只返回在当前日期注册的结果。我最近尝试过以下方法,但似乎没有效果。
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d')
FROM users
WHERE users.signup_date = CURDATE()
I've modified my SELECT
statement to this, thanks guys.
我修改了SELECT语句,谢谢大家。
SELECT id FROM users WHERE DATE(signup_date) = CURDATE()
从用户中选择日期(signup_date) = CURDATE()
3 个解决方案
#1
122
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d')
FROM users
WHERE DATE(signup_date) = CURDATE()
#2
13
This query will use index if you have it for signup_date
field
如果为signup_date字段提供索引,则该查询将使用索引
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d')
FROM users
WHERE signup_date >= CURDATE() && signup_date < (CURDATE() + INTERVAL 1 DAY)
#3
9
Sounds like you need to add the formatting to the WHERE
:
听起来您需要将格式添加到WHERE:
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d')
FROM users
WHERE DATE_FORMAT(users.signup_date, '%Y-%m-%d') = CURDATE()
参见SQL小提琴演示
#1
122
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d')
FROM users
WHERE DATE(signup_date) = CURDATE()
#2
13
This query will use index if you have it for signup_date
field
如果为signup_date字段提供索引,则该查询将使用索引
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d')
FROM users
WHERE signup_date >= CURDATE() && signup_date < (CURDATE() + INTERVAL 1 DAY)
#3
9
Sounds like you need to add the formatting to the WHERE
:
听起来您需要将格式添加到WHERE:
SELECT users.id, DATE_FORMAT(users.signup_date, '%Y-%m-%d')
FROM users
WHERE DATE_FORMAT(users.signup_date, '%Y-%m-%d') = CURDATE()
参见SQL小提琴演示