Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use DATE_ADD function in MySQL

Shulou Source: shulou.com Published: 2022-06-01 02:43:06 10月02日 Update

This article mainly introduces how to use the DATE_ADD function in MySQL, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand it.

DATE_ADD (date,INTERVAL number type), same as ADDDATE ()

SELECT DATE_ADD ("2015-12-31 23:59:59", INTERVAL 1 SECOND) SELECT DATE_ADD ("2015-12-31 23:59:59", INTERVAL 1 DAY) SELECT DATE_ADD ("2015-12-31 23:59:59", INTERVAL "1:1" MINUTE_SECOND) SELECT DATE_ADD ("2016-01-01 00:00:00" INTERVAL "- 1 10" DAY_HOUR)-> 2016-01-01 0000-> 2016-01-01 23-059-> 2016-01-01 00-01-01 00-01-0100-> 2015-12-30 14:00:00

DATE_ADD () and ADDDATE () return the result of the date operation

1. The format of date can be "15-12-31", "15-12-31 23:59:59" or "2015-12-31 23:59:59". If the parameter date is in date format, the result will be returned in date format. If the parameter date is in datetime format, the result in datetime format will be returned.

2. Type format:

SECOND second SECONDS

MINUTE minute MINUTES

HOUR time HOURS

DAY days DAYS

MONTH monthly MONTHS

YEAR year YEARS

MINUTE_SECOND minutes and seconds "MINUTES:SECONDS"

HOUR_MINUTE hours and minutes "HOURS:MINUTES"

DAY_HOUR days and hours "DAYS HOURS"

YEAR_MONTH year and month "YEARS-MONTHS"

HOUR_SECOND hours, minutes, "HOURS:MINUTES:SECONDS"

DAY_MINUTE days, hours, minutes "DAYS HOURS:MINUTES"

DAY_SECOND days, hours, minutes, seconds "DAYS HOURS:MINUTES:SECONDS"

3. In addition, if you do not use a function, you can also consider using the operator "+", "-". The example is as follows:

SELECT "2016-01-01"-INTERVAL 1 SECOND SELECT "2016-01-01"-INTERVAL 1 DAY SELECT '2016-12-31 23 INTERVAL 59' + INTERVAL 1 SECOND SELECT '2016-12-31 23 23 Fraser 59' + INTERVAL "1:1" MINUTE_SECOND

Return the result:

Thank you for reading this article carefully. I hope the article "how to use the DATE_ADD function in MySQL" shared by the editor will be helpful to all of you. At the same time, I hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Format hour article result function parameter no value example interest at the same time operator time more friends knowledge ribbon industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Linux MySQL Docker