
- 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
Add a single day to datetime field with MySQL INTERVAL
Let us first create a table −
mysql> create table DemoTable -> ( -> DueDate date ->); Query OK, 0 rows affected (2.11 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2018-12-31'); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values('2018-12-30'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('2017-02-26'); Query OK, 1 row affected (0.47 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-01-21 | | 2018-12-31 | | 2018-12-30 | | 2017-02-26 | +------------+ 4 rows in set (0.00 sec)
Here is the query to add a day to DateTime field in MySQL table −
mysql> update DemoTable -> set DueDate=date_add(DueDate,interval 1 day); Query OK, 4 rows affected (0.21 sec) Rows matched: 4 Changed: 4 Warnings: 0
Let us check the table records once again.
mysql> select *from DemoTable;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-01-22 | | 2019-01-01 | | 2018-12-31 | | 2017-02-27 | +------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to add a day to datetime field in MySQL query?
- How can I add one day to DATETIME field in MySQL query?
- Add DATE and TIME fields to get DATETIME field in MySQL?
- How to update date of datetime field with MySQL?
- MySQL Datetime to add days?
- Adding a day to a DATETIME format value in MySQL?
- Insert datetime into another datetime field in MySQL?
- How to convert char field to datetime field in MySQL?
- Compare DATE string with string from MySQL DATETIME field?
- How to add time in a MySQL column set with type DATETIME?
- How to ORDER BY FIELD with GROUP BY in a single MySQL query?
- Compare only day and month with date field in MySQL?
- Return a list from different rows into a single field with MySQL
- How to add 30 minutes to datetime in MySQL?
- Is there a way in MySQL to reverse a boolean field with a single query?

Advertisements