-
[MySQL] DATE_FORMAT() - 날짜 데이터의 출력 형식을 지정하는 함수DataBase/MySQL 2023. 2. 12. 21:55
문법
DATE_FORMAT(형식을 지정할 대상, '형식')
ex) SELECT DATE_FORMAT(PUBLISHED_DATE, '%Y-%m-%d') FROM BOOK
=> PUBLISHED_DATE 컬럼을 2021-03-01 형태로 출력
형식지정자 종류 및 설명
(이해가 안 되는 애들은 번역 pass.. 알게 될 때마다 차차 수정해보도록 하겠다.)
년도
형식 지정자 설명 %j 세 자리 수 년도 (001..366) %x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v %Y 네 자리 수 년도 (ex: 2023) %y 두 자리 수 년도 (ex: 23) 월
형식 지정자 설명 %b 축약된 영어 월 (Jan..Dec) %c 숫자형 월 (0..12) %D 서수형 월 (0th, 1st, 2nd, 3rd, …) %M 월 영어 풀네임 (January..December) %m 숫자형 두 자리 수 월 (00..12) 일
형식 지정자 설명 %e 숫자형 일 (0..31) %d 숫자형, 두 자리 수 일 (00..31) 요일
형식 지정자 설명 %a 축약된 영어 요일 (Sun..Sat) %U Week (00..53), where Sunday is the first day of the week; WEEK() mode 0 %u Week (00..53), where Monday is the first day of the week; WEEK() mode 1 %V Week (01..53), where Sunday is the first day of the week; WEEK() mode 2; used with %X %v Week (01..53), where Monday is the first day of the week; WEEK() mode 3; used with %x %W Weekday name (Sunday..Saturday) %w Day of the week (0=Sunday..6=Saturday) 시, 분, 초
형식 지정자 설명 %f 마이크로초 (000000..999999) %H 24시간제 두 자리수 시 (00..23) %k 24시간제 시 (0..23) %l 12시간제 시 (1..12) %I 12시간제 두 자리수 시 (01..12) %h 12시간제 두 자리수 시 (01..12) %i 두 자리 수 분 (00..59) %S 두 자리 수 초 (00..59) %s 두 자리 수 초 (00..59) %p AM or PM %r 12시간제 시각 (hh:mm:ss followed by AM or PM) %T 24시간제 시각 (hh:mm:ss) 기타
형식 지정자 설명 %% % 문자 그대로 출력 %x x, for any “x” not listed above Ref) https://dev.mysql.com/doc/refman/5.6/en/date-and-time-functions.html#function_date-format
MySQL :: MySQL 5.6 Reference Manual :: 12.7 Date and Time Functions
12.7 Date and Time Functions This section describes the functions that can be used to manipulate temporal values. See Section 11.2, “Date and Time Data Types”, for a description of the range of values each date and time type has and the valid formats
dev.mysql.com
'DataBase > MySQL' 카테고리의 다른 글
[프로그래머스] 조건에 맞는 도서와 저자 리스트 출력하기 - MySQL (0) 2023.02.12 [프로그래머스] 조건에 맞는 도서 리스트 출력하기 - MySQL (0) 2023.02.12 [프로그래머스] 주문량이 많은 아이스크림들 조회하기 - MySQ (0) 2023.02.02 [프로그래머스] 성분으로 구분한 아이스크림 총 주문량 - MySQL (0) 2023.02.01 [프로그래머스] 과일로 만든 아이스크림 고르기 - MySQL (0) 2023.02.01