DATE_PART()
field
: year, month, day 와 같은 날짜/시간 형태의 문자열soucre
: 실제 날짜/시간 값이다.
1
2
3
4
-- DATE_PART('field', source)
SELECT DATE_PART('year', '2023-04-26'); -> 2023
SELECT DATE_PART('month', '2023-04-26'); -> 4
SELECT DATE_PART('day', '2023-04-26'); -> 26
DATE_TRUNC()
1
2
3
4
-- DATE_TRUNC(text, timestamp)
SELECT DATE_TRUNC('month', '2019-04-01 12:12:12::timestamp') -> 2019-04-01 00:00:00
SELECT DATE_TRUNC('month', '2019-04-05 12:12:12::timestamp') -> 2019-04-01 00:00:00
SELECT DATE_TRUNC('year', '2019-04-01 12:12:12::timestamp') -> 2019-01-01 00:00:00