Home > Database > Mysql Tutorial > How to add 30 minutes to datetime in MySQL?

How to add 30 minutes to datetime in MySQL?

WBOY
Release: 2023-09-10 13:53:13
forward
1736 people have browsed it

如何在 MySQL 中向日期时间添加 30 分钟?

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;
Copy after login

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)
Copy after login

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)
Copy after login

Display the records in the table with the help of select statement. The query is as follows -

mysql> select *from Add30MinutesDemo;
Copy after login

The following is the output -

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

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;
Copy after login

The following is the output -

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template