How to add 30 minutes to datetime in MySQL?


To add minutes to a datetime you can use DATE_ADD() function from MySQL. In PHP, you can use strtotime().

To add 30 minutes in MySQL, the DATE_ADD() function is as follows −

select date_add(yourColumnName,interval 30 minute) from yourTableName;

To use the above syntax, let us create a table. The following is the query to create a table.

mysql> create table Add30MinutesDemo
   −> (
   −> YourTime datetime
   −> );
Query OK, 0 rows affected (0.67 sec)

Insert records in the table with the help of following query −

mysql> insert into Add30MinutesDemo values(now());
Query OK, 1 row affected (0.21 sec)

Display records from table with the help of select statement. The query is as follows −

mysql> select *from Add30MinutesDemo;

The following is the output −

+---------------------+
| YourTime            |
+---------------------+
| 2018-12-07 18:03:51 |
+---------------------+
1 row in set (0.00 sec)

Here is the MySQL query to add 30 minutes to a column. The query is as follows −

mysql> select date_add(YourTime,interval 30 minute) from Add30MinutesDemo;

The following is the output −

+---------------------------------------+
| date_add(YourTime,interval 30 minute) |
+---------------------------------------+
| 2018-12-07 18:33:51                   |
+---------------------------------------+
1 row in set (0.00 sec)

Updated on: 30-Jul-2019

13K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements