date_trunc is a function to truncate a timestamp value, or an interval value, with a level of precision.
This function has two argument:
- datapart is the level of precision
- field is the timestamp value or the interval value to truncate
Examples:
SELECT
date_trunc('month', '1/30/2020'::timestamp);
date_trunc
---------------------
2020-01-01 00:00:00
(1 row)
SELECT
date_trunc('month', '6 years 3 months 30 days'::interval);
date_trunc
----------------
6 years 3 mons
(1 row)
No comments:
Post a Comment