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

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: 2019-07-30T22:30:23+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements