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

MySQLMySQLi Database

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)
raja
Published on 29-Nov-2018 12:50:26
Advertisements