달나라 노트

Presto : year, quarter, month, week, week_of_year, day, day_of_month (날짜 성분 추출하기, 년도, 분기, 월, 주, 일) 본문

SQL/Presto

Presto : year, quarter, month, week, week_of_year, day, day_of_month (날짜 성분 추출하기, 년도, 분기, 월, 주, 일)

CosmosProject 2025. 10. 18. 11:42
728x90
반응형

 

 

 

Presto에서 사용할 수 있는 다양한 날짜 성분 추출 함수를 알아봅시다.

 

종류가 많으니 표로 정리하겠습니다.

Function name Description
year(datetime) 주어진 datetime의 년도를 추출합니다.
quarter(datetime) 주어진 datetime의 분기를 추출합니다.
month(datetime) 주어진 datetime의 월을 추출합니다.
week(datetime) 주어진 datetime의 주차를 추출합니다.
(1~53까지의 번호가 return될 수 있습니다.)
week_of_year(datetime) 주어진 datetime의 1년중 주차를 추출합니다.
(week 함수와 동일합니다.)
day(datetime) 주어진 datetime의 일을 추출합니다.
day_of_month(datetime) 주어진 datetime의 해당 월에서의 일을 추출합니다.
(day 함수와 동일합니다.)

 

 

 

select  current_timestamp as current_dttm  --> 2025-10-18 02:40:06.391

        , year(current_timestamp) as current_year  --> 2025
        
        , quarter(current_timestamp) as current_quarter  --> 4
        
        , month(current_timestamp) as current_month  --> 10
        
        , week(current_timestamp) as current_week  --> 42
        , week_of_year(current_timestamp) as current_week_of_year  --> 42
        
        , day(current_timestamp) as current_day  --> 18
        , day_of_month(current_timestamp) as current_day_of_month  --> 18
;

 

실제 예시를 보면 위와 같습니다.

current_timestamp의 결과는 현재 시점의 timestamp를 보여주는데

각 날짜함수의 결과와 비교해보면 현재 시점에서의 년도, 분기, 월, 주, 일 정보를 제대로 보여주는 것을 알 수 있습니다.

 

 

 

 

FYI

https://prestodb.io/docs/current/functions/datetime.html#dow-x-bigint

 

Date and Time Functions and Operators - Presto 0.295 Documentation

Date and Time Functions and Operators Date and Time Operators Operator Example Result + date '2012-08-08' + interval '2' day 2012-08-10 + time '01:00' + interval '3' hour 04:00:00.000 + timestamp '2012-08-08 01:00' + interval '29' hour 2012-08-09 06:00:00.

prestodb.io

 

 

 

 

 

 

 

 

 

728x90
반응형
Comments