SQL

MySQL 날짜변환

MDanderson 2022. 10. 24. 19:49

DATE_FORMAT(날짜형식의  칼럼명or값, "%Y-%m-%d" )

%Y  2022       %y   22

%m 02            %b Fab                               %c  2

%d 28

%a Sat           %W   Saturday

 

%H  00 ~23

%h 00~12

 

%i  00~59 분

%s 00~59초

 

@

hour(DATETIME칼럼명 )  하면 시간만 추출됨. 

 

@

date("2022-05-01") 하면 날짜로변환. 

 

 

Format Description

%a Abbreviated weekday name (Sun to Sat) 요일 명을 Sun to Sat 으로
%b Abbreviated month name (Jan to Dec) 월 별 이름을 Jan to Dec 으로
%c Numeric month name (0 to 12) 월 별 이름을 0 ~12 로
%D Day of the month as a numeric value, followed by suffix (1st, 2nd, 3rd, ...) 일 이름을 1st, 2nd,... 으로 
%d Day of the month as a numeric value (01 to 31)  
%e Day of the month as a numeric value (0 to 31)  
%f Microseconds (000000 to 999999)  
%H Hour (00 to 23)  
%h Hour (00 to 12)  
%I Hour (00 to 12)  
%i Minutes (00 to 59)  
%j Day of the year (001 to 366)  
%k Hour (0 to 23) 24시간 표기법으로
%l Hour (1 to 12) 12시간 표기법으로
%M Month name in full (January to December) 달 이름을 Full Name으로
%m Month name as a numeric value (00 to 12) 달 이름을 00~12 숫자로 
%p AM or PM PM, AM 표시
%r Time in 12 hour AM or PM format (hh:mm:ss AM/PM)  
%S Seconds (00 to 59)  
%s Seconds (00 to 59)  
%T Time in 24 hour format (hh:mm:ss) 24시간 표기법으로 
%U Week where Sunday is the first day of the week (00 to 53)  
%u Week where Monday is the first day of the week (00 to 53)  
%V Week where Sunday is the first day of the week (01 to 53). Used with %X  
%v Week where Monday is the first day of the week (01 to 53). Used with %x  
%W Weekday name in full (Sunday to Saturday) 요일 이름을 Full Name으로
%w Day of the week where Sunday=0 and Saturday=6 Sunday=0~Saturday=6 으로
%X Year for the week where Sunday is the first day of the week. Used with %V 일주일의 시작을 일요일
%x Year for the week where Monday is the first day of the week. Used with %v 일주일의 시작을 월요일
%Y Year as a numeric, 4-digit value 년도 표현 4자리로
%y Year as a numeric, 2-digit value 년도 표현 2자리로

출처: https://bramhyun.tistory.com/28 [日日新又日新:티스토리]

'SQL' 카테고리의 다른 글

SQL 가격대 별 상품 개수 구하기 (MySQL)  (0) 2022.10.25
SQL 문자열 자르기  (0) 2022.10.25
SQL if문 case문  (0) 2022.10.25
SQL null값 추출  (0) 2022.10.24
SQL null값 치환(대체)  (0) 2022.10.24