웹이야기

MySQL SUBDATE() 본문

D/MySQL

MySQL SUBDATE()

yeon.Biju 2020. 4. 3. 10:05

MySQL 날짜함수, 시간함수

 

SUBDATE()

   - 날짜를 빼줄 수 있는 함수, 사용방법은 2가지.

   - DATE_ADD(), DATE_SUB()와 유사.

   - 날짜를 뺄 때 -도 가능하므로 날짜 더하기 빼기 모두 가능하다.

 

SUBDATE(date, INTERVAL expr unit)

SUBDATE(expr, days)

의 형태

 

When invoked with the INTERVAL form of the second argument, SUBDATE() is a synonym for DATE_SUB(). For information on the INTERVAL unit argumet. see the disussion for DATE_ADD().

 

https://webobj.tistory.com/114

 

MySQL DATE_ADD(), DATE_SUB()

MySQL 날짜함수, 시간함수 DATE_ADD(), DATE_SUB() - 날짜 더하기 , 빼기 DATE_ADD(date, INTERVAL expr unit) DATE_SUB(date, INTERVAL expr unit) 의 형태 These functions perform date arithmetic. The date a..

webobj.tistory.com

 

mysql> SELECT DATE_SUB('2008-01-02', INTERVAL 31 DAY);
+-----------------------------------------+
| DATE_SUB('2008-01-02', INTERVAL 31 DAY) |
+-----------------------------------------+
| 2007-12-02                              |
+-----------------------------------------+
1 row in set (0.00 sec)

 

mysql> SELECT SUBDATE('2008-01-02', INTERVAL 31 DAY);
+----------------------------------------+
| SUBDATE('2008-01-02', INTERVAL 31 DAY) |
+----------------------------------------+
| 2007-12-02                             |
+----------------------------------------+
1 row in set (0.00 sec)

 

 

The second form enables the use of an integer value for days. In such cases, it is interpreted as the number of days to be substracted from the date or datetime expression expr.

 

mysql> SELECT SUBDATE('2008-01-02 12:00:00', 31);
+------------------------------------+
| SUBDATE('2008-01-02 12:00:00', 31) |
+------------------------------------+
| 2007-12-02 12:00:00                |
+------------------------------------+
1 row in set (0.00 sec)

 

 

mysql> SELECT SUBDATE('2008-01-02 12:00:00', -31);
+-------------------------------------+
| SUBDATE('2008-01-02 12:00:00', -31) |
+-------------------------------------+
| 2008-02-02 12:00:00                 |
+-------------------------------------+
1 row in set (0.00 sec)

 

 


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

 

 

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

MySQL SYSDATE()  (0) 2020.04.03
MySQL SUBTIME()  (0) 2020.04.03
MySQL STR_TO_DATE()  (0) 2020.04.03
MySQL SEC_TO_TIME()  (0) 2020.04.03
MySQL SECOND()  (0) 2020.04.03
Comments