We can use the following query to get the date difference from a date or even we can use to compare to get the desired result.
SELECT DATE_SUB(CURDATE(),INTERVAL 21 DAY)
It gives the 21 days before date from today date.
Or even we can use it on comparision after WHERE statement as following:
AND DATE_SUB(CURDATE(),INTERVAL 21 DAY) <= FROM_UNIXTIME(date_field,’%Y-%m-%d %h:%i:%s’)
It will display the 21 days ago rows if the date_field is numeric value (FROM_UNIXTIME is used to convert into standard unix time).
If date_field is already in %Y-%m-%d format, then we can use as
AND DATE_SUB(CURDATE(),INTERVAL 21 DAY) <= date_field
This type of query is used in displaying the results for 1 week result or 2 weeks or 3 weeks or 1 year etc.