MySQL DATE_ADD(date,INTERVAL expr type) and ADDDATE(date,INTERVAL expr type) functions have the same function, both are used to perform date addition operations. The DATE_ADD() and ADDDATE() functions have two parameters:
[Example 1] Use the DATE_ADD(date,INTERVAL expr type) function to perform date addition operations. The input SQL statement and the execution result are as follows. mysql> SELECT DATE_ADD('2018-10-31 23:59:59',INTERVAL 1 SECOND) AS C1, -> DATE_ADD('2018-10-31 23:59:59',INTERVAL '1:1' MINUTE_SECOND) AS C2, -> ADDDATE('2018-10-31 23:59:59',INTERVAL 1 SECOND) AS C3; +---------------------+---------------------+---------------------+ | C1 | C2 | C3 | +---------------------+---------------------+---------------------+ | 2018-11-01 00:00:00 | 2018-11-01 00:01:00 | 2018-11-01 00:00:00 | +---------------------+---------------------+---------------------+ 1 row in set (0.00 sec) From the execution results, we can see that the functions of DATE_ADD(date,INTERVAL expr type) and ADDDATE(date,INTERVAL expr type) are exactly the same. After adding 1 second to the original time '2018-10-31 23:59:59', the result is '2018-11-01 00:00:00'; adding 1 minute and 1 second to the original time is the expression '1:1', and the final result is '2018-11-01 00:01:00'. [Example 2] Use the ADDDATE() function to perform date addition operations. The input SQL statement and execution results are shown below. mysql> SELECT ADDDATE('2017-11-30 23:59:59', INTERVAL 1 SECOND) AS col1, -> ADDDATE('2017-11-30 23:59:59' ,INTERVAL '1:1' MINUTE_SECOND) AS col2; +---------------------+---------------------+ | col1 | col2 | +---------------------+---------------------+ | 2017-12-01 00:00:00 | 2017-12-01 00:01:00 | +---------------------+---------------------+ 1 row in set (0.02 sec) From the running results, we can see that the result of the ADDDATE('2017-11-30 23:59:59', INTERVAL 1 SECOND) function execution increases the time by 1 second and returns the result as "2017-12-01 00:00:00"; the date operation type of the ADDDATE('2017-11-30 23:59:59', INTERVAL'1:1'MINUTE_SECOND) function is MINUTE_SECOND, which increases the specified time by 1 minute and 1 second and returns the result as "2017-12-01 00:01:00". This is the end of this article about MySQL DATE_ADD and ADDDATE functions to add specified time intervals to dates. For more information about MySQL specified time intervals, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Application of HTML and CSS in Flash
>>: Detailed explanation of CSS counter related attributes learning
Table of contents 2. Detailed explanation 2.1. Ad...
1. Introduction Responsive Web design allows a we...
Table of contents Application scenarios: Method 1...
1. Overview of SQLException When an error occurs ...
Here are some problems encountered in the use of ...
1. Use Centos image to build local yum source Sin...
Table of contents 1. Install Docker 2. Write code...
This article shares the specific code of JavaScri...
Managing disk space is an important daily task fo...
Table of contents 1. Introduction 2. Solution Imp...
Before we use JSX to build a component system, le...
Preface In the development of actual projects, we...
1. Check the database time zone show variables li...
This article will not explain the use and install...
This article records the installation and configu...