SQL · Functions and expressions

date_trunc()

Truncates a timestamp to a unit, ideal for grouping by period.

Syntax
date_trunc('month', ts)

Example

Open in the lab

More in this group

cast() concat() cte current_date / now() exists extract() Greatest / least lag() / lead()

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course