MySQL's now() +1 day?


The statement now()+1 day itself states that we need to add a day to the current datetime. You can write the above logic like this −

now()+interval 1 day;

Or you can write same logic with date_add() function from MySQL like this −

date_add(now(),interval 1 day);

Let us use the above concept with MySQL select statement. The query is as follows −

mysql> select now()+ interval 1 day;

Here is the sample output that increments a day by 1 −

+-----------------------+
| now()+ interval 1 day |
+-----------------------+
| 2018-11-23 15:43:10   |
+-----------------------+
1 row in set (0.05 sec)

Now, let us see another example to use the date_add() function for adding a day to the current date.

The query is as follows −

mysql> select date_add(now(),interval 1 day);

Here is the output −

+--------------------------------+
| date_add(now(),interval 1 day) |
+--------------------------------+
| 2018-11-23 15:45:43            |
+--------------------------------+
1 row in set (0.00 sec)

For displaying only the date, then you can use the below logic for now()+1 day.

Use curdate(), instead of now().

curdate()+interval 1 day.

Or you can use the above logic with the help of date_add() function.

date_add(curdate(),interval 1 day);

Here is demo of the above two concepts.

mysql> select curdate()+interval 1 day;

Here is the output that displays only the incremented date with curdate() −

+--------------------------+
| curdate()+interval 1 day |
+--------------------------+
| 2018-11-23               |
+--------------------------+
1 row in set (0.00 sec)

The date_add() demo −

mysql> select date_add(curdate(),interval 1 day);

Here is the output that displays only the incremented date with date_add() −

+------------------------------------+
| date_add(curdate(),interval 1 day) |
+------------------------------------+
| 2018-11-23                         |
+------------------------------------+
1 row in set (0.00 sec)

Updated on: 30-Jul-2019

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements