What is the usage of the SQL date_sub function?
The DATE_SUB() function is used to subtract a specified time interval from a date. Its syntax is as follows:
DATE_SUB(date, INTERVAL expr unit)
date is the date from which the time interval is subtracted, expr is the quantity of the time interval to subtract, and unit is the unit of the time interval (such as DAY, WEEK, MONTH, YEAR, etc.).
For example, to subtract 1 day from the current date, you can use the following SQL statement:
SELECT DATE_SUB(NOW(), INTERVAL 1 DAY);
This will give the result of subtracting 1 day from the current date.