
- 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
MySQL add days to a date?
To add days to a date, you can use DATE_ADD() function from MySQL. The syntax is as follows to add days to a date −
INSERT INTO yourTableName VALUES(DATE_ADD(now(),interval n day));
In the above syntax, you can use curdate() instead of now(). The curdate() will store only date while now() will store both date and time.
Here is the demo of both the functions. To understand the above syntax, let us create a table.
mysql> create table addingDaysDemo −> ( −> yourDateTime datetime −> ); Query OK, 0 rows affected (1.09 sec)
Use both the above both functions now() and curdate() in insert statement and use “interval” to add days. The query to add days to a date is as follows −
mysql> insert into addingDaysDemo values(date_add(now(),interval 1 day)); Query OK, 1 row affected (0.14 sec) mysql> insert into addingDaysDemo values(date_add(now(),interval 4 day)); Query OK, 1 row affected (0.17 sec) mysql> insert into addingDaysDemo values(date_add(now(),interval 5 day)); Query OK, 1 row affected (0.14 sec) mysql> insert into addingDaysDemo values(date_add(now(),interval 7 day)); Query OK, 1 row affected (0.17 sec) mysql> insert into addingDaysDemo values(date_add(now(),interval 9 day)); Query OK, 1 row affected (0.15 sec) mysql> insert into addingDaysDemo values(date_add(curdate(),interval 1 day)); Query OK, 1 row affected (0.18 sec) mysql> insert into addingDaysDemo values(date_add(curdate(),interval 4 day)); Query OK, 1 row affected (0.16 sec) mysql> insert into addingDaysDemo values(date_add(curdate(),interval 5 day)); Query OK, 1 row affected (0.17 sec) mysql> insert into addingDaysDemo values(date_add(curdate(),interval 7 day)); Query OK, 1 row affected (0.12 sec) mysql> insert into addingDaysDemo values(date_add(curdate(),interval 9 day)); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from addingDaysDemo;
The following is the output −
+---------------------+ | yourDateTime | +---------------------+ | 2018-12-14 15:36:57 | | 2018-12-17 15:37:06 | | 2018-12-18 15:37:12 | | 2018-12-20 15:37:17 | | 2018-12-22 15:37:21 | | 2018-12-14 00:00:00 | | 2018-12-17 00:00:00 | | 2018-12-18 00:00:00 | | 2018-12-20 00:00:00 | | 2018-12-22 00:00:00 | +---------------------+ 10 rows in set (0.00 sec)
- Related Articles
- Add 11 days to current date in MySQL
- Add 30 days to date in a MySQL table with arrival date records
- How to add a year and two days to a date with a single MySQL query?
- MySQL Datetime to add days?
- How to add days to $Date in PHP?
- How to add number of days to JavaScript Date?
- C# DateTime to add days to the current date
- MySQL query to delete a DATE older than 30 days from another date?
- Add 30 days to a value in a MySQL table?
- Java Program to add days to current date using Java Calendar
- Add two weeks to a date in MySQL?
- How to add some days to str_to_date() MySQL function?
- MySQL query to count days in date range with start and end date
- MySQL query to fetch date more recent than 14 days?
- How Add or Subtract Specific Years, Months and Days to a Date in Excel?

Advertisements