Josh Josh - 5 days ago 3
MySQL Question

SQL: Query for date greater than X months and Y days ago

Is it possible to construct a SQL query for MySQL that can

SELECT
based on a date being greater than 1 month and 4 days ago?

I know that the following is possible:

SELECT * FROM TBL WHERE DATE_COL > date_sub(now(), INTERVAL 1 MONTH);


However, what if I wanted to add another 4 days (or any number of days for that matter) to the interval in the date_sub?

Answer

You should be able to wrap it:

SELECT * FROM TBL 
WHERE DATE_COL > date_sub(date_sub(now(), INTERVAL 1 MONTH), INTERVAL 4 DAY);
Comments