Skip to content
Blog

Timestamp functions

Timestamp functions are used to create and extract fields from timestamps.

FunctionDescriptionExampleResult
century(timestamp)returns the century of the timestampcentury(TIMESTAMP('2013-12-11 14:22:13'))21 (INT64)
date_part(part, timestamp)returns the subfield of the timestampdate_part('second', TIMESTAMP('1995-11-02 12:05:21'))21 (INT64)
datepart(part, timestamp)alias of date_partdatepart('month', TIMESTAMP('1926-11-21 13:22:19'))11 (INT64)
date_trunc(part, timestamp)returns the given timestamp with specified precisiondate_trunc('month', TIMESTAMP('2002-10-21 13:51:21'))2002-10-01 00:00:00 (TIMESTAMP)
datetrunc(part, timestamp)alias of date_truncdatetrunc('year', TIMESTAMP('2005-12-11 11:21:31'))2005-01-01 00:00:00 (TIMESTAMP)
dayname(timestamp)returns the calendar day of the timestampdayname(TIMESTAMP('2022-11-08 11:12:20'))Tuesday (STRING)
epoch_ms(ms)converts the ms to timestampepoch_ms(INT64(701222402100))1992-03-22 00:00:02.1 (TIMESTAMP)
greatest(timestamp, timestamp)returns the later of the two timestampsgreatest(TIMESTAMP('2013-12-11 10:22:11'), TIMESTAMP('2011-05-13 13:22:11'))2013-12-11 10:22:11 (TIMESTAMP)
least(timestamp, timestamp)returns the earlier of the two timestampsleast(TIMESTAMP('1966-12-21 15:22:11'), TIMESTAMP('2005-11-12'))1966-12-21 15:22:11 (TIMESTAMP)
last_day(timestamp)returns the last day of the month of the timestamplast_day(TIMESTAMP('2022-11-08 05:11:31'))2022-11-30 (DATE)
monthname(timestamp)returns the english name of the month of the datemonthname(TIMESTAMP('2022-04-21 06:11:22'))April (STRING)
to_timestamp(sec)converts sec to timestampto_timestamp(701222723)1992-03-22 00:05:23 (TIMESTAMP)