MySQL – Subtract Time Value (Intervals) From Date

MySQL DATE_SUB() function allow you to substract a time value (Intervals) from the selected date.

MySQL SUBDATE() function is the synonym of DATE_SUB() function.

The following examples will return a date after substracting 10 days from the specified date 2014-01-15.

Syntax – DATE_SUB() Function

Example:

Output:

Syntax – SUBDATE() Function

Example-1:

Output:

Example-2:

Output:

Arguments

Name Description
date Date or datetime value
INTERVAL Keyword
expr An expression specifying the interval value
unit Keyword indicating the units

The following table shows the expected form of the expr argument for each unit value.

unit Value Expected expr Format
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS
SECOND_MICROSECOND 'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND 'MINUTES:SECONDS.MICROSECONDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSECOND 'HOURS:MINUTES:SECONDS.MICROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
DAY_MICROSECOND 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH 'YEARS-MONTHS'

3 Responses to MySQL – Subtract Time Value (Intervals) From Date

  1. Nice blog here! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host? I wish my site loaded up as quickly as yours lol
    stivali ugg saldi http://www.enterpriseengine.com/wp-content/themes/twentythirteen/ugg-outlet/PJLqiI8qnh/

Leave a Reply

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