Cute Happy Ghost
본문 바로가기
DB/Postgresql

[postgresql] 현재시간, 시간 yyyy-mm-dd hh24:mi:ss 등으로 포맷하여 변환하기, interval 사용하여 현재시간보다 10분전 조회

by JENN_tech7 2022. 8. 4.
728x90
SMALL

내가 원하는 것: 현재 시간의 분까지의 데이터를 조회하는 것

예 : 2022-08-04 11:30의 데이터를 조회하기, 현재시간을 원하는 형태로 포맷하여 조회

 

select to_timestamp('2013-11-24 11:29:87', 'YYYY-MM-DD HH24:MI');
select to_timestamp(now()::varchar, 'YYYY-MM-DD HH24:MI');

 

 

 

 

예: 현재시간보다 10분전의 시간 

to_timestamp((now() - interval '10 minute')::varchar, 'YYYY-MM-DD HH24:MI')

 

 

참고ref

https://stackoverflow.com/questions/20180460/how-to-convert-yyyymmddhhmmss-to-2013-11-24-112907-in-postgres

 

how to convert YYYYMMDDHHMMSS to 2013-11-24 11:29:07 in postgres

Postgres char(14) fields stores datetime withou separators like 20131124112907 How to add separators so that result is string in format 2013-11-24 11:29:07 I tried Denis answer using to_timestamp(

stackoverflow.com

 

728x90
LIST

댓글