Computer >> Computer tutorials >  >> Programming >> MySQL

DATEADD or DATE_ADD in MySQL query?


You need to use DATE_ADD() in MySQL.

The syntax is as follows

DATE_ADD(NOW(), INTERVAL yourValue MINUTE);

Arithmetic operator can also be used.

The syntax is as follows

NOW() + INTERVAL 30 MINUTE

Here is the demo of DATE_ADD() function.

The query is as follows

mysql> select date_add(now(), interval 30 minute);

The following is the output

+-------------------------------------+
| date_add(now(), interval 30 minute) |
+-------------------------------------+
| 2019-02-27 15:38:27                 |
+-------------------------------------+
1 row in set (0.00 sec)

Let us now use arithmetic + operator instead of DATE_ADD().

The query is as follows

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2019-02-27 15:09:18 |
+---------------------+
1 row in set (0.00 sec)

Now add 30 minutes in NOW().

The query is as follows

mysql> select now()+interval 30 minute;

The following is the output

+--------------------------+
| now()+interval 30 minute |
+--------------------------+
| 2019-02-27 15:39:33      |
+--------------------------+
1 row in set (0.00 sec)