How to subtract 30 days from the current datetime in mysql?
To anyone who doesn't want to use DATE_SUB
, use CURRENT_DATE
:
SELECT CURRENT_DATE - INTERVAL 30 DAY
SELECT * FROM table
WHERE exec_datetime BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY) AND NOW();
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add