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
Preface Because computer numbers are floating poi...
environment Host IP 192.168.0.9 Docker version 19...
Brief description <br />In IE6 and 7, in a ...
Hello everyone, I am Liang Xu. When using Linux, ...
If you want to wrap the text in the textarea input...
1. Introduction to nmon Nmon (Nigel's Monitor...
After installing the latest version 8.0.11 of mys...
Notes on installing MySQL database, share with ev...
Table of contents Tutorial Series 1. Introduction...
When changing the time zone under Linux, it is al...
1. Install Docker 1. I installed Centos7 in the v...
Preface: Because many business tables use design ...
1. Refer to the official website to install docke...
Installation suggestion : Try not to use .exe for...
The accessibility of web pages seems to be somethi...