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

MySQL how to add or subtract datetime

WBOY
WBOYforward
2023-05-27 11:27:22826browse

Add/decrease date and time

Command:

DATE_ADD(date,interval expr unit)
DATE_SUB(date,interval expr unit)

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)

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete