SQL Date Function DATE_SUB()

www.igift‮aedi‬.com

The DATE_SUB() function is a SQL function used to subtract a specified interval of time from a date or datetime value. It takes three arguments: the first argument is the date or datetime value to be subtracted from, the second argument is the interval of time to subtract, and the third argument is the unit of time for the interval.

The interval can be specified as a number of years, months, days, hours, minutes, or seconds. The unit of time is specified as a string, such as "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", or "SECOND".

Here's an example of how to use the DATE_SUB() function in a SQL query:

SELECT DATE_SUB('2022-02-28', INTERVAL 1 MONTH);

This query will return a date value that is one month before the date "2022-02-28", which is "2022-01-28".

Note that the DATE_SUB() function is specific to the database management system you are using, and the syntax and units of time it supports may vary slightly depending on the system.