Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use DATE_ADD function in MySQL

2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 202

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report