DB/MYSQL

[MYSQL] DAYOFWEEK() /현재 요일 한글로 출력

보겸삼촌 2020. 3. 2. 15:33

-- DAYOFWEEK(날짜) -> 1(일요일)~7(토요일) 출력
select DAYOFWEEK(CURDATE()) as WEEKS;


1. 한글 요일로 출력
  1.1. CASE WHEN THEN END 사용

select DAYOFWEEK(curdate()) as BEFORE_DATE,
  case DAYOFWEEK(CURDATE())
	   when '1' then '일'
	   when '2' then '월'
	   when '3' then '화'
	   when '4' then '수'
	   when '5' then '목'
	   when '6' then '금'
	   when '7' then '토'
   end as AFTER_DATE;

 

  1.2. SUBSTR 사용

select DAYOFWEEK(CURDATE()) AS BEFORE_DATE, SUBSTR(_UTF8'일월화수목금토', DAYOFWEEK(CURDATE()), 1) as AFTER_DATE ;