일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- Date and Time Function
- 방화벽
- MySQL
- Sring Functions and Operators
- String Functions and Operators
- 전자정부표준프레임워크
- HTTP
- SVN
- String Functions and Date Operators
- Oracle
- Tibero
- String Function and Operators
- 티베로
- 윈도우
- Date and Time Functions
- Data and Time Functions
- 전자정부 표준프레임워크
- 오라클
- Today
- Total
웹이야기
MySQL SUBDATE() 본문
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> 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 |