Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 직장인점심
- 주니어개발자
- 성수
- 성수맛집
- 성수핫플
- Java
- 객체지향
- 성수직장인
- 성수볼거리
- 헤드퍼스트디자인패턴
- JavaScript
- 오브젝트
- DesignPattern
- 코딩
- 헤드퍼스트
- Linux
- 책너두
- IntelliJ
- docker
- 디자인패턴
- 책읽기
- 개발자
- 독서
- 깨끗한코드
- JAVA개발자
- 독서일지
- 상속
- 객체지향프로그래밍
- 직장인
- 클린코드
Archives
- Today
- Total
런타임노트
[mariaDB/Mysql] date format 날짜 시간 형식 표현 본문
728x90
[DB]MariaDB/Mysql date_format 날짜 시간 형식 표현
쿼리에서 형식에서 대소문자 유의하셔야 됩니다.
아래에 쿼리로 진행했을경우 YYYY-MM-DD HH:MM:SS 이런식에 결과를 보이게 됩니다.
SELECT date_format(NOW(), '%Y-%m-%d %T' ) as date

하지만 만약에 '%Y-%M-%D %T' 이런식으로 진행된다면 어떤 결과가 나올까요?
실제 저도 처음에는 대수롭지 않게 이렇게 보고 쳤습니다.
SELECT date_format(NOW(), '%Y-%M-%D %T' ) as date

위하고는 전혀 다른 결과를 얻게 됩니다.
MariaDB 날짜 형식표 및 예시
| 포맷(Format) | 설명 |
| %M | 월(Janeary, December, ...) |
| %W | 요일(Sunday, Monday, ...) |
| %D | 월(1st, 2dn, 3rd, ...) |
| %Y | 연도(1987, 2000, 2013) |
| %y | 연도(87, 00, 13) |
| %X | 연도(1987, 2000) %V와 같이 쓰임 |
| %x | 연도(1987, 2000) %v와 같이 쓰임 |
| %a | 요일(Sun, Tue, ...) |
| %d | 일(00, 01, 02, ...) |
| %e | 일(0, 1, 2, ...) |
| %c | 월(1, 2, ..., 12) |
| %b | 월(Jan, Feb, Mar ...) |
| %j | 몇번째 일(120, 365) |
| %H | 시(00, 01, 02, 13, 24) |
| %h | 시(01, 02, 12) |
| %I(대문자 영문아이) | 시(01, 02, 12) |
| %l(소문자 영문엘) | 시(1, 2, 12) |
| %i | 분(00, 01, 30) |
| %r | hh:mm:ss AM|PM (시분초 오전|오후) |
| %T | hh:mm:ss (시분초) |
| %S | 초 |
| %s | 초 |
| %p | AM, PM |
| %w | 요일(0,1,2) 0:일요일 |
| %U | 주(시작:일요일) |
| %u | 주(시작:월요일) |
| %V | 주(시작:일요일) |
| %v | 주(시작:월요일) |
예시)
SELECT NOW();
▼ 결과 ( 2021-03-22 23:32:44 )

SELECT now(), date_format(NOW(), '%M' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%W' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%D' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%Y' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%y' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%X' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%x' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%a' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%d' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%e' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%c' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%b' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%j' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%H' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%h' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%I' ) as date
▼ 대문자 아이(i) 입력 결과

SELECT now(), date_format(NOW(), '%l' ) as date
▼ 소문자 엘(l) 입력 결과

SELECT now(), date_format(NOW(), '%i' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%r' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%T' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%S' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%s' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%p' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%w' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%U' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%u' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%V' ) as date
▼ 결과

SELECT now(), date_format(NOW(), '%v' ) as date
▼ 결과

728x90
반응형
'DB' 카테고리의 다른 글
| [TIBERO] docker tibero (0) | 2024.04.09 |
|---|---|
| [DB] Direct database rename is not yet implemented in MySQL. You should use export/import functions for that. | db name rename 하기 (0) | 2023.10.16 |
| [MariaDB] IF, IFNULL, NULLIF (2) | 2023.04.18 |
| ER 다이어그램, ERD 기호 및 표기법 (2) | 2023.02.27 |
| [MariaDB] 날짜 하루 더하기 (0) | 2023.02.24 |