닭발개발

[mariaDB/Mysql] date format 날짜 시간 형식 표현 본문

DB

[mariaDB/Mysql] date format 날짜 시간 형식 표현

D269 2023. 3. 23. 16:14
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

▼ 결과 

 

 

 

 

 

 

 

 

출처 : https://itworldyo.tistory.com/70

728x90
반응형