타임스탬프
문자열과 타임스탬프 타입간의 상호 변환
Section titled “문자열과 타임스탬프 타입간의 상호 변환”- 문자열 -> 타임스탬프
SELECT STR_TO_DATE('20260311_182236', '%Y%m%d_%H%i%s');
- 타임스탬프 -> 문자열
SELECT DATE_FORMAT(NOW(), '%Y%m%d_%H%i%s');
중요 포맷 지정자
Section titled “중요 포맷 지정자”| No. | 지정자 | 비고 |
|---|---|---|
| 1 | %Y | 4자리 연도 (예: 2023) |
| 2 | %m | 월 (01~12) |
| 3 | %d | 일 (01~31) |
| 4 | %H | 시간 (00~23) |
| 5 | %i | 분 (00~59) |
| 6 | %s | 초 (00~59) |
BETWEEN 연산자를 사용해서 타임스탬프 타입 비교
Section titled “BETWEEN 연산자를 사용해서 타임스탬프 타입 비교”- 테스트
select t.inner_date between t.from_date and t.to_date as inside, t.outer_date between t.from_date and t.to_date as outsidefrom ( select (select str_to_date('20260101', '%Y%m%d')) as from_date, (select str_to_date('20260131', '%Y%m%d')) as to_date, (select str_to_date('20260105', '%Y%m%d')) as inner_date, (select str_to_date('20260315', '%Y%m%d')) as outer_date) as t
- 출력결과
+--------+---------+| inside | outside |+--------+---------+| 1 | 0 |+--------+---------+1 row in set (0.001 sec)