I need to sort the result of my SQL query by date using WHERE. I want to know how I can get the result between the actual date and 6 months earlier.
Sort of
BETWEEN actual_date AND actual_date - (operator) 6 month
thanks
try it
SELECT * FROM table WHERE actual_date BETWEEN DATE_ADD(Now(),INTERVAL -6 MONTH) AND Now()
If there was an initial error, since it was 6 months ago, the lower date should be the first.
You can do it:
WHERE mydate BETWEEN DATE_SUB( NOW(), INTERVAL 6 MONTH) AND NOW()
I'm not in front of a MySQL terminal, but this should work
select * from yourtable t where /* Greater or equal NOW */ r.date >= NOW() /* Smaller or equal than 6 months ago */ r.date <= DATE_SUB(NOW(), INTERVAL 6 MONTH)
SELECT * FROM table WHERE actual_date BETWEEN DATE_ADD(actual_date,INTERVAL -6 MONTH) AND actual_date or SELECT * FROM table WHERE actual_date BETWEEN DATE_SUB( actual_date, INTERVAL 6 MONTH) AND actual_date