Home >Database >Mysql Tutorial >How to add 30 minutes to datetime in MySQL?
To add minutes to a datetime, you can use the DATE_ADD() function in 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;
In order to use the above syntax, let us create a table. Below is the query to create the table.
mysql> create table Add30MinutesDemo −> ( −> YourTime datetime −> ); Query OK, 0 rows affected (0.67 sec)
Insert records in the table with the help of the following query -
mysql> insert into Add30MinutesDemo values(now()); Query OK, 1 row affected (0.21 sec)
Display the records in the 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)
This is the MySQL query to add 30 minutes to the 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)
The above is the detailed content of How to add 30 minutes to datetime in MySQL?. For more information, please follow other related articles on the PHP Chinese website!