Skip to content

Supported Date Parts

You can use the date parts in the table as arguments to the following functions:

Date parts can be specified in uppercase or lowercase.

DatepartDescriptionNotes
epochEpochNot supported for DATEADD.
millennia, mil, milsMillennium
centuries, century, cent, cCentury
decades, decade, decsDecade
years, year, yrs, yr, yYearSee datestyle Support for Year Values.
quarter, qtrQuarter
months, month, mons, monMonthRepresented as 1 through 12 with 1 being January.Returns in sentence case for DATENAME (for example, January).

weeks, week, wWeekReturns ISO 8601 week numbers, 1 to 53.
days, day, dDays
dowDay of WeekNot supported for DATEADD.Represented as 0 through 6 with 0 being Sunday.

Returns in sentence case for DATENAME (for example, Monday).

doyDay of YearNot supported for DATEADD.
isodowISO 8601 Day of WeekNot supported for DATEADD.
isoyearISO 8601 Day of Year
hours, hour, hrs, hr, hHours
minutes, minute, mins, min, mMinutes
seconds, second, secs, sec, sSeconds
useconds, usecond, usecs, usec, usMicroseconds
millisecon, mseconds, msecond, msecs, msec, msMilliseconds
timezoneTime zone offset from UTC, in seconds (the difference between local time and UTC). Positive values correspond to time zones east of UTC, negative values to zones west of UTC.Supported only for EXTRACT and DATE_PART. The timezone, timezone_hour, and timezone_minute date parts operate only on timestamptz columns and expressions. For Infinity, +inf, and -inf, EXTRACT and DATE_PART return 0.

timezone_hourHour component of the time zone offset.
timezone_minuteMinute component of the time zone offset.

datestyle Support for Year Values

Yellowbrick supports either a 4-digit year (YYYY) or a 2-digit year (YY). However, the default datestyle setting is MDY, which expects a 2-digit month to be the first value in the date string. Therefore, queries that attempt to cast strings to dates but specify 2-digit years at the beginning of the string return "value out of range" errors. For example:

yellowbrick=> show datestyle;
 DateStyle 
-----------
 ISO, MDY
(1 row)

yellowbrick=> select days_between(now(), '99-10-20');
ERROR:  The month value of 99 is out of range
LINE 1: select days_between(now(), '99-10-20');
                                  ^
yellowbrick=> set datestyle = 'ISO, YMD';
SET
yellowbrick=> select days_between(now(), '99-10-20');
 days_between 
--------------
        8629
(1 row)

See also ybload Date Formats.