달나라 노트

Presto : to_char (날짜를 문자로 변환, convert date to text) 본문

SQL/Presto

Presto : to_char (날짜를 문자로 변환, convert date to text)

CosmosProject 2025. 10. 3. 16:57
728x90
반응형

 

 

 

Presto에서는 Redshift에서와 비슷한 to_char 함수를 제공합니다.

날짜/시간을 텍스트로 바꿔주는 역할을 합니다.

 

 

Syntax

to_char(datetime, format)

 

- datetime

to_char를 적용할 대상 datetime 값입니다.

 

- format

어떠한 Format으로 바꿀지를 나타냅니다.

특정한 기호를 이용하여 바꿀 수 있습니다.

아래는 날짜 기호를 나타냅니다.

Keyword Meaning
yyyy 4자리 년도
yy 2자리 년도
mm 2자리 월(01 ~ 12)
dd 2자리 일(01~31)
hh24 24시 기준 시간(00~23)
hh 12시 기준 시간(1~12)
mi 2자리 분(00~59)
ss 2자리 초(00~59)

 

 

 

 

select  to_char(current_date, 'yyyymmdd')  --> 20251225
        , to_char(current_date, 'yyyy-mm-dd')  --> 2025-12-25
        , to_char(current_date, 'yyyymmdd hh24miss')  --> 20251225 000000
        , to_char(current_timestamp, 'yyyymmdd')  --> 20251225
        , to_char(current_timestamp, 'yyyymmdd hh24miss')  --> 20251225 135642
;

 

 

 

 

 

 

 

 

 

 

728x90
반응형
Comments