Skip to main content

Date Parts

The date_part and date_diff and date_trunc functions can be used to manipulate the fields of temporal types. The fields are specified as strings that contain the part name of the field.

Part Specifiers

Below is a full list of all available date part specifiers. The examples are the corresponding parts of the timestamp 2021-08-03 11:59:44.123456.

Usable as Date Part Specifiers and in Intervals

SpecifierDescriptionSynonymsExample
'century'Gregorian century'cent', 'centuries', 'c'21
'day'Gregorian day'days', 'd', 'dayofmonth'3
'decade'Gregorian decade'dec', 'decades', 'decs'202
'hour'Hours'hr', 'hours', 'hrs', 'h'11
'microseconds'Sub-minute microseconds'microsecond', 'us', 'usec', 'usecs', 'usecond', 'useconds'44123456
'millennium'Gregorian millennium'mil', 'millenniums', 'millenia', 'mils', 'millenium'3
'milliseconds'Sub-minute milliseconds'millisecond', 'ms', 'msec', 'msecs', 'msecond', 'mseconds'44123
'minute'Minutes'min', 'minutes', 'mins', 'm'59
'month'Gregorian month'mon', 'months', 'mons'8
'quarter'Quarter of the year (1-4)'quarters'3
'second'Seconds'sec', 'seconds', 'secs', 's'44
'year'Gregorian year'yr', 'y', 'years', 'yrs'2021

Usable in Date Part Specifiers Only

SpecifierDescriptionSynonymsExample
'dayofweek'Day of the week (Sunday = 0, Saturday = 6)'weekday', 'dow'2
'dayofyear'Day of the year (1-365/366)'doy'215
'epoch'Seconds since 1970-01-011627991984
'era'Gregorian era (CE/AD, BCE/BC)1
'isodow'ISO day of the week (Monday = 1, Sunday = 7)2
'isoyear'ISO Year number (Starts on Monday of week containing Jan 4th)2021
'timezone'Time zone offset in seconds0
'timezone_hour'Time zone offset hour portion0
'timezone_minute'Time zone offset minute portion0
'week'Week number'weeks', 'w'31
'yearweek'ISO year and week number in YYYYWW format202131

Note that the time zone parts are all zero unless a time zone plugin such as ICU has been installed to support TIMESTAMP WITH TIME ZONE.

Part Functions

There are dedicated extraction functions to get certain subfields:

FunctionDescriptionExampleResult
century(date)Centurycentury(date '1992-02-15')20
day(date)Dayday(date '1992-02-15')15
dayofmonth(date)Day (synonym)dayofmonth(date '1992-02-15')15
dayofweek(date)Numeric weekday (Sunday = 0, Saturday = 6)dayofweek(date '1992-02-15')6
dayofyear(date)Numeric ISO weekday (Monday = 1, Sunday = 7)isodow(date '1992-02-15')46
decade(date)Decade (year / 10)decade(date '1992-02-15')199
epoch(date)Seconds since 1970-01-01epoch(date '1992-02-15')698112000
era(date)Calendar eraera(date '0044-03-15 (BC)')0
hour(date)Hourshour(timestamp '2021-08-03 11:59:44.123456')11
isodow(date)Numeric ISO weekday (Monday = 1, Sunday = 7)isodow(date '1992-02-15')6
isoyear(date)ISO Year number (Starts on Monday of week containing Jan 4th)isoyear(date '2022-01-01')2021
microsecond(date)Sub-minute microsecondsmicrosecond(timestamp '2021-08-03 11:59:44.123456')44123456
millennium(date)Millenniummillennium(date '1992-02-15')2
millisecond(date)Sub-minute millisecondsmillisecond(timestamp '2021-08-03 11:59:44.123456')44123
minute(date)Minutesminute(timestamp '2021-08-03 11:59:44.123456')59
month(date)Monthmonth(date '1992-02-15')2
quarter(date)Quarterquarter(date '1992-02-15')1
second(date)Secondssecond(timestamp '2021-08-03 11:59:44.123456')44
timezone(date)Time Zone offset in minutestimezone(date '1992-02-15')0
timezone_hour(date)Time zone offset hour portiontimezone_hour(date '1992-02-15')0
timezone_minute(date)Time zone offset minutes portiontimezone_minute(date '1992-02-15')0
week(date)ISO Weekweek(date '1992-02-15')7
weekday(date)Numeric weekday synonym (Sunday = 0, Saturday = 6)weekday(date '1992-02-15')6
weekofyear(date)ISO Week (synonym)weekofyear(date '1992-02-15')7
year(date)Yearyear(date '1992-02-15')1992
yearweek(date)BIGINT of combined ISO Year number and 2-digit version of ISO Week numberyearweek(date '1992-02-15')199207