I need to show in a query some items between the current date of the time in question and two years before.
I need to show in a query some items between the current date of the time in question and two years before.
Use BETWEEN
with date_sub
to subtract a range from the entered date:
SELECT * FROM table WHERE data BETWEEN NOW() AND DATE_SUB(NOW(), INTERVAL 2 YEAR);