본문 바로가기
공부한 거/SQL

[MySQL] DATE_FORMAT

by freakFlow 2023. 10. 13.

https://dev.mysql.com/doc/refman/8.1/en/date-and-time-functions.html#function_date-format

 

MySQL :: MySQL 8.1 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

DATE_FORMAT(date, format)

date 값을 format 문자열에 맞는 형식으로 반환한다. 두 매개변수 중 하나라도 NULL이면 NULL을 반환한다.

%가 앞에 붙는 specifier를 사용한다.

 

Specifiers

Specifier Descriptoin
%a Abbreviated weekday name (Sun, ..., Sat)
%b Abbreviated month name (Jan, ..., Dec)
%c Month, numeric (0, ..., 12)
%D Day of the month with English suffix (0th, 1st, 2nd, 3rd, ...)
%d Day of the month, numeric (00, ..., 31)
%e Day of the month, numeric (0, ..., 31)
%f Microseconds (000000, ..., 999999)
%H Hour (00, ..., 23)
%h Hour (01, ..., 12)
%I (대문자 i) Hour (01, ..., 12)
%i Minutes, numeric (00, ..., 59)
%j Day of year (001, ..., 366)
%k Hour (0, ..., 23)
%l (소문자 L) Hour (1, ..., 12)
%M Month name (January, ..., December)
%m Month, numeric (00, ..., 12)
%p AM or PM
%r Time, 12-hour (hh:mm:ss followed by AM or PM)
%S Seconds (00, ..., 59)
%s Seconds (00, ..., 59)
%T Time, 24-hour (hh:mm:ss)
%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)
%X Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%x Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%Y Year, numeric, four digits
%y Year, numeric (two digits)
%% A literal % character
%x x, for any "x" not listed above

%c, %d와 같이 0을 지원하는 이유는 MySQL이 '2014-00-00'과 같이 불완전한 날짜도 저장이 되기 때문이다.

'공부한 거 > SQL' 카테고리의 다른 글

[MySQL] BETWEEN  (0) 2023.10.17
[MySQL] LIMIT  (0) 2023.10.16