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 Preface What is VirtualDOM? Rea...
MySQL foreign key constraint (FOREIGN KEY) is a s...
Introduction to Swap Swap (i.e. swap partition) i...
In Node.js, a .js file is a complete scope (modul...
Install the unzipped version of Mysql under win10...
Transaction A transaction is a basic unit of busi...
Table of contents 1. What is an index? 2. Why do ...
This article uses examples to explain the princip...
Docker basic instructions: Update Packages yum -y...
Achieve results Implementation Code html <div ...
Table of contents 1. Parent component passes valu...
Public name of the page: #wrapper - - The outer e...
Recently, a system was deployed, using nginx as a...
Table of contents 1. Aggregate Query 1. COUNT fun...
<br />The solution steps are as follows: Sta...