Fetch rows with DATE
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 r开发者_运维百科ows that were created within the last 24 hours?
Joel
Try this:
SELECT * FROM table WHERE date >= DATE_SUB(NOW(), INTERVAL 24 HOUR))
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);
精彩评论