Appearance
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.
Datepart | Description | Notes |
---|---|---|
epoch | Epoch | Not supported for DATEADD. |
millennia, mil, mils | Millennium | |
centuries, century, cent, c | Century | |
decades, decade, decs | Decade | |
years, year, yrs, yr, y | Year | See datestyle Support for Year Values. |
quarter, qtr | Quarter | |
months, month, mons, mon | Month | Represented as 1 through 12 with 1 being January.Returns in sentence case for DATENAME (for example, January ). |
weeks, week, w | Week | Returns ISO 8601 week numbers, 1 to 53 . |
days, day, d | Days | |
dow | Day of Week | Not supported for DATEADD.Represented as 0 through 6 with 0 being Sunday.Returns in sentence case for DATENAME (for example, Monday ). |
doy | Day of Year | Not supported for DATEADD. |
isodow | ISO 8601 Day of Week | Not supported for DATEADD. |
isoyear | ISO 8601 Day of Year | |
hours, hour, hrs, hr, h | Hours | |
minutes, minute, mins, min, m | Minutes | |
seconds, second, secs, sec, s | Seconds | |
useconds, usecond, usecs, usec, us | Microseconds | |
millisecon, mseconds, msecond, msecs, msec, ms | Milliseconds | |
timezone | Time 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_hour | Hour component of the time zone offset. | |
timezone_minute | Minute 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.