현재 날짜 구하기
select current_date as today;
현재 날짜/시간 구하기
select now() as today;
select current_timestamp as today;
하루 전/후 날짜 구하기
select date '2023-07-04' + integer '-1';
select now() + '-1 days';
select date '2023-07-04' + integer '1';
select now() + '1 days';
일주일 전/후 날짜 구하기
select date '2023-07-04' + integer '-7';
select now() + '-1 week';
select date '2023-07-04' + integer '7';
select now() + '1 week';
한달 전/후 날짜 구하기
select now() + '-1 month';
select now() + '1 month';
일년 전/후 날짜 구하기
select now() + '-1 year';
select now() + '1 year';
지난 달의 날짜 구하기
select date_trunc('month', date '2023-04-15') + '-1 days';
-> 2023-03-31 00:00:00.000 +0900
select date_trunc('month', date '2023-07-04') + '-1 days';
-> 2023-06-30 00:00:00.000 +0900
[참고]
https://yaruki0318.tistory.com/entry/PostgreSQL%EC%9D%98-%EB%82%A0%EC%A7%9C-%EA%B3%84%EC%82%B0
'분석가 Step 1. 데이터 분석 > SQL' 카테고리의 다른 글
[PostgreSQL] UNION과 UNION ALL (0) | 2023.07.31 |
---|---|
SQL, 실무에 적용하기 위한 연습 사이트 W3Schools (0) | 2023.07.27 |
[PostgreSQL] 날짜의 요일 코드와 요일 구하기 (0) | 2023.07.26 |
PostgreSQL 설치, 데이터베이스와 연동하기 (0) | 2023.06.29 |
SQL 실력 향상을 위한 해커랭크(HackerRank) 시작하기 (0) | 2023.03.22 |