Calculate a relative date in the past.
Section: date and time functions
Subtract an interval
sql
sql
SELECT DATE_SUB(NOW(), INTERVAL 30 DAY) AS thirty_days_ago;Explanation
Handy for rolling windows and recent-activity filters.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing date and time functions