SQL DATE_SUB

The SQL DATE_SUB is a mySql function, unlike SQL DATE_ADD function which add time value, SQL DATE_SUB will subtract time values (intervals) from a date value.

SQL DATE_SUB Syntax

DATE_SUB(date-expression, INTERVAL expr type)

For the type, please refer to the SQL ADDDATE() function.

SQL DATE_SUB Examples

SELECT DATE_SUB('2010-08-12', INTERVAL 3 DAY) AS NewDate

Result: 2010-08-09

SELECT DATE_SUB('2010-08-12', INTERVAL '3-2' YEAR_MONTH) AS NewDate

Result: 2007-06-12

SELECT DATE_SUB('2011-09-14 2:44:36', INTERVAL '2:26' HOUR_MINUTE) AS NewDate

Result: 2011-09-14 00:18:36

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>