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. Is this possible?
So right now a user cannot enter more than once in a 24 hour period. 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.
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.
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.
Change NOW()
to CURDATE()
, that should solve your problem.