
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Is there a way to subtract number of days from a date in MySQL?
Yes, you can use date_sub() to subtract number of days from a date. Following is the syntax −
select date_sub(yourColumnName,Interval yourAmountOfDays day) from yourTableName;
Let us first create a table −
mysql> create table DemoTable660(AdmissionDate datetime); Query OK, 0 rows affected (0.82 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable660 values('2018-01-24'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable660 values('2019-07-10'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable660 values('2020-11-20'); Query OK, 1 row affected (0.59 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable660;
This will produce the following output −
+---------------------+ | AdmissionDate | +---------------------+ | 2018-01-24 00:00:00 | | 2019-07-10 00:00:00 | | 2020-11-20 00:00:00 | +---------------------+ 3 rows in set (0.00 sec)
Following is the query to subtract number of days from a date in MySQL −
mysql> select date_sub(AdmissionDate,Interval 5 day) from DemoTable660;
This will produce the following output −
+----------------------------------------+ | date_sub(AdmissionDate,Interval 5 day) | +----------------------------------------+ | 2018-01-19 00:00:00 | | 2019-07-05 00:00:00 | | 2020-11-15 00:00:00 | +----------------------------------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to subtract number of days from a date to get the previous date in R?
- How to subtract days from a date in JavaScript?
- Subtract days from current date using Calendar.DATE in Java
- Is there a way to make a list from a MySQL table in Java?
- Is there a way to change the date format in php?
- Fastest way to search for a date from the date records in MySQL
- MySQL add days to a date?
- MySQL query to delete a DATE older than 30 days from another date?
- How to subtract 30 days from the current datetime in MySQL?
- How to subtract 10 days from the current datetime in MySQL?
- How to subtract seconds from all the date records in a MySQL column?
- Is there a way to know your current username in MySQL?
- How Add or Subtract Specific Years, Months and Days to a Date in Excel?
- Is there any way to use values from a JSON object in a MySQL Select statement?\n
- Is there a way to retrieve the minimum value of fields in MySQL?

Advertisements