How to subtract 10 days from the current datetime in MySQL?


Firstly, let us get the current datetime with the help of the now() function.

mysql> select now();

The following is the output.

+---------------------+
| now()               |
+---------------------+
| 2018-11-01 19:55:56 |
+---------------------+
1 row in set (0.00 sec)

Syntax to subtract 10 days with the help of DATE_SUB()

select DATE_SUB(now(),interval integer_value day );

Applying the above syntax to subtract 10 days from the current datetime.

mysql> select DATE_SUB(now(),interval 10 day);

Here is the output.

+---------------------------------+
| DATE_SUB(now(),interval 10 day) |
+---------------------------------+
| 2018-10-22 19:56:07             |
+---------------------------------+
1 row in set (0.00 sec)

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements