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)

Updated on: 12-Dec-2019

99 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements