What is the purpose of the SQL date_sub function?

The DATE_SUB function in SQL is used to subtract a specified time interval from a given date. It takes three parameters: the date to subtract the interval from, the amount of time to subtract, and the unit of time to subtract (such as DAY, MONTH, YEAR, etc.).

For example, DATE_SUB(‘2022-01-01’, INTERVAL 1 MONTH) will return 2021-12-01, which means subtracting 1 month from the date of January 1, 2022.

The DATE_SUB function is often used to calculate the difference between dates or for date manipulation in SQL queries.

bannerAds