웹이야기

MySQL ADDDATE() 본문

D/MySQL

MySQL ADDDATE()

yeon.Biju 2020. 4. 1. 10:40

MySQL 날짜함수, 시간함수

 

ADDDATE()

 

ADDDATE(date, INTERVAL expr unit)

또는

ADDDATE(expr, days) 형태

 

When invoked with the INTERVAL form of the second argument, ADDDATE() is a synonym for DATE_ADD(). The related function SUBDATE() is a synonym for DATE_SUB(). For information on the INTERVAL unit argument.

 

mysql> SELECT DATE_ADD('2001-01-02', INTERVAL 31 DAY);                                                                          +-----------------------------------------+
| DATE_ADD('2001-01-02', INTERVAL 31 DAY) |
+-----------------------------------------+
| 2001-02-02                              |
+-----------------------------------------+
1 row in set (0.00 sec)


mysql> SELECT ADDDATE('2001-01-02', INTERVAL 31 DAY);
+----------------------------------------+
| ADDDATE('2001-01-02', INTERVAL 31 DAY) |
+----------------------------------------+
| 2001-02-02                             |
+----------------------------------------+
1 row in set (0.00 sec)

 

mysql> SELECT ADDDATE('2001-01-02', 31) ;
+---------------------------+
| ADDDATE('2001-01-02', 31) |
+---------------------------+
| 2001-02-02                |
+---------------------------+
1 row in set (0.00 sec)

 

 

 

INTERVAL unit 으로 쓸 수 있는 것들

unit value Expected expr Format
MICROSECOND MICROSECONDS
SECOND SECONDS
MINUTE MINUTES
HOUR HOURS
DAY DAYS
WEEK WEEKS
MONTH MONTHS
QUARTER QUARTERS
YEAR YEARS
SECOND_MICROSECOND 'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND 'MINUTES:SECONDS.MICROSECONDS'
MINUTE_SECOND 'MINUTES:SECONDS'
HOUR_MICROSECOND 'HOURS:MINUTES:SECONDS.MICROSECONDS'
HOUR_SECOND 'HOURS:MINUTES:SECONDS'
HOUR_MINUTE 'HOURS:MINUTES'
DAY_MICROSECOND 'DAYS
HOURS:MINUTES:SECONDS.MICROSECONDS'
DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE 'DAYS HOURS:MINUTES'
DAY_HOUR 'DAYS HOURS'
YEAR_MONTH 'YEARS-MONTHS'

 

 

'D > MySQL' 카테고리의 다른 글

MySQL CONVERT_TZ()  (0) 2020.04.01
MySQL ADDTIME()  (0) 2020.04.01
MySQL Date and Time Functions  (0) 2020.03.31
MySQL TRUNCATE()  (0) 2020.03.29
MySQL SIN()  (0) 2020.03.29
Comments