개발 한 스푼/MySQL

[MySQL] YEAR_MONTH() 현재 연도, 월 알아내기

idleday 2023. 7. 17. 14:06

MySQL 날짜함수, 시간함수

 

EXTRACT()

   -  날짜에서 년, 월, 일, 시간등을 추출

 

EXTRACT(unit FROM date)

의 형태

 

The EXTRACT() function uses the same kinds of unit specifiers as DATE_ADD() or DATE_SUB(), but extracts parts from the date rather than performing date arithmetic.

 

 

 

YEAR_MONTH from date

 

SELECT CONCAT(YEAR(NOW()), MONTH(NOW()));	-- 20237

 

SELECT EXTRACT(YEAR_MONTH FROM NOW());		-- 202307

 

 

 


ref

https://learnsql.com/cookbook/how-to-get-the-year-and-the-month-from-a-date-in-mysql/

 

How to Get the Year and the Month From a Date in MySQL

Problem: You want to get the year and the month from a given date in a MySQL database. Example: Our database has a table named dates with data in the columns id and date. iddate 12008-04-21 21987-12-14 Let’s extract the year and the month from the date.

learnsql.com