Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

MySQL SUBDATE Function

by suresh

MySQL SUBDATE function is one of the Date Functions, which is a synonym of the DATE_SUB function. This MySQL SUBDATE function is used to subtract the user-specified intervals from the given date and returns the date and time.

The basic syntax of the SUBDATE() Function in MySQL is as shown below:

SUBDATE(Date, INTERVAL expression Unit);

SUBDATE(Date expression, days);

MySQL SUBDATE function Example

The below-shown queries help you understand the use of this SUBDATE function. Here, we are subtracting 8 Microseconds, 8 Seconds, and 8 Minutes from the given DateTime expression.

TIP: I suggest you refer to the Date Functions article to understand the Units after the Interval in MySQL.

SELECT SUBDATE('2016-05-19 11:14:34.0000010', INTERVAL 8 MICROSECOND);

SELECT SUBDATE('2016-05-19 11:14:34.0000010', INTERVAL 8 SECOND);

SELECT SUBDATE('2016-05-19 11:14:34.0000010', INTERVAL 8 MINUTE);

OUTPUT

MySQL SUBDATE Function 1

In this example, we are subtracting 8 Hours, 6 days from the given DateTime expression. Within the third statement, we haven’t used the Interval. It means we used the second syntax of the MySQL subdate function.

SELECT SUBDATE('2019-02-09 11:14:34', INTERVAL 8 HOUR);

SELECT SUBDATE('2019-02-09 11:14:34', INTERVAL 6 DAY);

SELECT SUBDATE('2019-02-09 11:14:34', 6);

OUTPUT

MySQL SUBDATE Function 2

In this MySQL SUBDATE function example, we are subtracting 6 Weeks, 6 Months, and 2 Quarters from the given DateTime expression.

SELECT SUBDATE('2019-02-09 11:14:34', INTERVAL 6 WEEK);

SELECT SUBDATE('2019-02-09 11:14:34', INTERVAL 6 MONTH);

SELECT SUBDATE('2019-02-09 11:14:34', INTERVAL 2 QUARTER);

OUTPUT

MySQL SUBDATE Function 3

Here,

  • First, subtracted 4 Years
  • The second statement – subtracted 5 days and 8 hours from the given date.
  • Within the third statement, we subtracted 3 years and 8 months.
SELECT SUBDATE('2019-02-09 11:14:34', INTERVAL 4 YEAR);

SELECT SUBDATE('2019-02-09 11:14:34', INTERVAL '05 08' DAY_HOUR);

SELECT SUBDATE('2019-02-09', INTERVAL '03-08' YEAR_MONTH);

OUTPUT

MySQL SUBDATE Function 4

Placed Under: MySQL

  • How to Download MySQL
  • Install MySQL on Windows
  • MySQL Create Database
  • MySQL Delete Database
  • MySQL Create Table
  • MySQL Drop Table
  • MySQL SELECT Statement
  • MySQL ALIAS Column
  • MySQL Distinct
  • MySQL Insert Statement
  • MySQL Delete
  • MySQL Truncate Table
  • MySQL WHERE Clause
  • MySQL Order By
  • MySQL Group By
  • MySQL Having Clause
  • MySQL LIMIT
  • MySQL Arithmetic Operators
  • MySQL COALESCE Function
  • MySQL AND Operator
  • MySQL NOT Operator
  • MySQL OR Operator
  • MySQL XOR Operator
  • MySQL BETWEEN Operator
  • MySQL Not Between Operator
  • MySQL GREATEST Function
  • MYSQL LEAST Function
  • MySQL LIKE Operator
  • MySQL NOT LIKE Operator
  • MySQL IFNULL Operator
  • MySQL NULLIF Operator
  • MySQL INTERVAL Operator
  • MySQL IS Operator
  • MySQL IN Operator
  • MySQL NOT IN Operator
  • MySQL IS NOT NULL
  • MySQL IS NULL
  • MySQL Inner Join
  • MySQL Cross Join
  • MySQL Right Join
  • MySQL Left Join
  • MySQL Aggregate Functions
  • MySQL Date Functions
  • MySQL Date Function
  • MySQL String Functions
  • MySQL Numeric Functions
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy