SQL/Redshift

Redshift : current_date, sysdate, getdate (현재 날짜, 현재 시간 얻기)

CosmosProject 2021. 8. 25. 19:43
728x90
반응형

 

 

 

 

Redshift에서 현재 날짜 또는 현재 시간을 추출할 수 있는 방법을 알아봅시다.

 

 

select current_date;



-- Result
2021-08-25

먼저 current_date입니다.

current_date는 현재 날짜를 반환해줍니다.

 

 

 

 

select to_char(current_date, 'yyyymmdd');



-- Result
20210825

current_date로 반환되는 날짜의 data type은 날짜이기때문에 to_char 함수와 같이 사용할 수 있습니다.

 

 

 

 

 

select  sysdate,   --> 2021-08-25 19:38:52.382610
        getdate()  --> 2021-08-25 19:38:52.000000
;

sysdate와 getdate 함수는 현재 날짜와 시간을 반환해줍니다.

다만 getdate 함수는 소수점 초단위는 모두 0으로 return해주며

sysdate 함수는 소수점 초단위까지 모두 return해줍니다.

 

 

 

 

select to_char(sysdate, 'yyyymmdd'),    --> 20210825
       to_char(getdate(), 'yyyymmdd')   --> 20210825
;

마찬가지로 sysdate 함수는 날짜시간 type의 데이터를 반환하므로 위처럼 사용가능합니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형