Home > Database > Mysql Tutorial > MySQL how to add or subtract datetime

MySQL how to add or subtract datetime

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-05-27 11:27:22
forward
850 people have browsed it

Add/decrease date and time

Command:

DATE_ADD(date,interval expr unit)
DATE_SUB(date,interval expr unit)
Copy after login

Function: increase/decrease date and time

Application scenario: the day before the current time , a few minutes ago. Often used in data statistics.

Example:

mysql> select date_add(now(),interval 1 day);
+--------------------------------+
| date_add(now(),interval 1 day) |
+--------------------------------+
| 2017-12-28 20:10:17  |
+--------------------------------+
1 row in set (0.00 sec)
Copy after login

Date represents the date format, including: such as

2017-12-27, now() and other formats.

expr: indicates the quantity.

unit: Represents the unit, supporting milliseconds (microsecond), seconds (second), hours (hour), days (day), weeks (week), years (year), etc.

The above is the detailed content of MySQL how to add or subtract datetime. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template