user784637 user784637 - 6 months ago 27
SQL Question

How to subtract 30 days from the current datetime in mysql?

How do I subtract 30 days from the current datetime in mysql?

SELECT * FROM table
WHERE exec_datetime BETWEEN DATEDIFF(NOW() - 30 days) AND NOW();

Answer
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