Date Truncate Function

The date_trunc function supports the given below units. The examples in the table use timestamp 2000-08-05T09:05:10 as an input.

unitTruncated example value

second

2000-08-05T09:05:10

minute

2000-08-05T09:05:00

hour

2000-08-05T09:00:00

day

2000-08-05T00:00:00

week

2000-07-31T00:00:00

month

2000-08-01T00:00:00

quarter

2000-07-01T00:00:00

year

2000-01-01T00:00:00

DATE_TRUNC( unit, <datetime_expr> )

Returns the input expression truncated to a given unit (refer above table).

Supported datatype : Date/Timestamp

 > select date_trunc('year' , '2022-03-23');
 2022-01-01T00:00:00.000+00:00

TRUNC( <datetime_expr>, unit )

Returns the input expression truncated to a given unit (refer above table).

Supported datatype : Date/Timestamp

 > select trunc(date '2022-09-03', 'month');
 2022-09-01T00:00:00.000+00:00
 > select trunc(timestamp '2022-09-03 12:04:08' , 'hour');
 2022-09-03T12:00:00.000+00:00

Last updated