반응형
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- google apps script
- gas
- PostgreSQL
- string
- 파이썬
- GIT
- PySpark
- Tkinter
- Google Spreadsheet
- django
- Python
- Presto
- matplotlib
- Java
- Kotlin
- Github
- list
- PANDAS
- Apache
- c#
- hive
- Google Excel
- array
- math
- dataframe
- numpy
- Redshift
- Excel
- SQL
Archives
- Today
- Total
달나라 노트
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:42728x90
반응형
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
반응형
'SQL > Presto' 카테고리의 다른 글
| Presto : dow, day_of_week (요일 추출, weekday) (0) | 2025.10.18 |
|---|---|
| Presto : last_day_of_month (특정 월의 마지막 날짜 구하기) (0) | 2025.10.18 |
| Presto : date_parse (문자를 날짜/시간으로 변환, convert text to date/time) (0) | 2025.10.03 |
| Presto : to_char (날짜를 문자로 변환, convert date to text) (0) | 2025.10.03 |
| Presto : substring, substr (문자열 추출하기, 문자열 자르기) (0) | 2025.10.03 |
Comments
