DATE_SUB
DATE_SUB(date, INTERVAL expr type)
Section titled “DATE_SUB(date, INTERVAL expr type)”- date: This parameter specifies the date from which the interval needs to be subtracted. It must be a valid date value that MySQL supports, including date expressions that return a date or datetime value.
- interval expr type: The INTERVAL keyword and its following expression (expr) mean to subtract a certain time interval from the date we have in the first parameter. It has two parts
Example
Section titled “Example”SELECT DATE_SUB('2008-01-02', INTERVAL 31 DAY);Output
Section titled “Output”'2007-12-02'Explanation
Section titled “Explanation”The above example demonstrates the usage of DATE_SUB function in MySQL. It subtracts a time interval from the provided date. In this case the interval is 31 days, subtracted from ‘2008-01-02’, which results in ‘2007-12-02’.