Reputation: 6107
I am storing rows with MySQL using a date col. Everytime I insert a new row I use date=CURDATE() . Is there anyway I can run a SELECT statement that selects all rows that were created within the last 24 hours?
Joel
Upvotes: 0
Views: 101
Reputation: 101483
You can use the sub_date()
function with interval
to make a range of dates between now and 24 hours ago:
SELECT * FROM table WHERE date_field BETWEEN curdate() AND DATE_SUB(curdate(), INTERVAL 1 DAY);
Upvotes: 1
Reputation: 9480
Try this:
SELECT * FROM table WHERE date >= DATE_SUB(NOW(), INTERVAL 24 HOUR))
Upvotes: 1