[Database] MySQL DAY, MONTH, YEAR, EXTRACT 관련 함수


DAY, MONTH, YEAR 관련 함수

DAY(), WEEK(), WEEKOFYEAR(), MONTH(), YEAR()

SELECT DAY(CURDATE()), WEEK(CURDATE()), WEEKOFYEAR(CURDATE()), MONTH(CURDATE()), YEAR(CURDATE());
  • 쿼리 결과

DAYOFYEAR(), DAYOFMONTH(), DAYOFWEEK(), WEEKDAY()

  • DAYOFWEEK( ) : 일=1, … , 토=7
  • WEEKDAY( ) : 월=0, … , 일=6
SELECT DAYOFYEAR(CURDATE()), DAYOFMONTH(CURDATE()), DAYOFWEEK(CURDATE()), WEEKDAY(CURDATE());
  • 쿼리 결과

LAST_DAY()

LAST_DAY(date)
SELECT LAST_DAY(CURDATE());
  • 쿼리 결과

DAYNAME(), MONTHNAME()

DAYNAME( date ), MONTHNAME( date )
SELECT DAYNAME(CURDATE()), MONTHNAME(CURDATE());
  • 쿼리 결과

YEARWEEK(()

YEARWEEK( date )
SELECT YEARWEEK(CURDATE());
  • 쿼리 결과

EXTRACT()

  • DATE로 부터 년, 월, 일, 시, 분, 초 등을 추출
EXTRACT( unit FROM date )
SELECT EXTRACT(YEAR FROM CURDATE());

SELECT EXTRACT(YEAR_MONTH FROM CURDATE());
  • 쿼리 결과