EXTRACT and DATE_PART
Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API Partial Data 360 Apps
Retrieves a subfield, such as the year or hour, from a date, time, timestamp, or interval value. EXTRACT and date_part are equivalent. Use EXTRACT for computational processing. To display date or time values as formatted text, see Formatting Functions.
<field>: An identifier or string that selects the field to extract from the source value.EXTRACTanddate_partsupport the same field options. For valid options, see Fields.<source>: The value to extract the field from. Must be an expression of typedate,timestamp,timestamptz,time, orinterval. These functions cast values of typedatetotimestamp.
<fiscal_option>: A fiscal calendar option that defines the start date of the fiscal calendar.<source>must be of typedate,timestamp, ortimestamptz, and<field>must befiscal_week,fiscal_month,fiscal_quarter, orfiscal_year. See Fiscal Calendar Options.<localized_week_option>: A localized week option that defines the start of a week and a year.<source>must be of typedate,timestamp, ortimestamptz, and<field>must belocalized_week. See Localized Week Options.
The result type of EXTRACT depends on the field:
numeric(8,6)for the fieldsecondnumeric(18,6)for the fieldepochintegerfor any other field
The result type of date_part is always double precision, independent of the selected field.
- Data 360 Apps:
EXTRACTandDATE_PARTdon’t support thetimezone,timezone_hour,timezone_minute,fiscal_month,fiscal_quarter,fiscal_week, orfiscal_yearfields.DATE_PARTalso doesn’t support the'ago','julian','timezonehour', or'timezoneminute'field values. - Data 360 Apps: Extracting
localized_weekis supported fordateandtimestamptzinputs, but not fortimestampinputs.
centuryThe century. The first century starts at 0001-01-01 00:00:00 AD. There's no century number 0.
dayFor
timestampvalues, the day of the month (1–31). Forintervalvalues, the number of days.decadeThe year field divided by 10.
dowThe day of the week as Sunday (
0) to Saturday (6).doyThe day of the year (1–365/366).
epochFor
timestamp with time zonevalues, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative). Fordateandtimestampvalues, the number of seconds since 1970-01-01 00:00:00 local time. Forintervalvalues, the total number of seconds in the interval.To convert an epoch value back to a timestamp, use
to_timestamp.fiscal_monthThe month within the fiscal year (1–12).
fiscal_quarterThe quarter within the fiscal year (1–4).
fiscal_weekThe week within the fiscal year (1–54).
fiscal_yearThe fiscal year.
hourThe hour field (0–23).
isodowThe day of the week as Monday (
1) to Sunday (7). This is identical todowexcept for Sunday.isoyearThe ISO 8601 week-numbering year that the date falls in (not applicable to intervals). Each ISO 8601 week-numbering year begins with the Monday of the week containing January 4. In early January or late December, the ISO year can differ from the Gregorian year. See the
weekfield for more information.localized_weekThe week within the year with a custom start date, determined by the
first_day_of_localized_weekandminimal_days_in_localized_first_weekparameters. See Localized Week Options for a detailed explanation and examples.microsecondsThe seconds field, including fractional parts, multiplied by 1,000,000.
millenniumThe millennium. Years in the 1900s are in the second millennium. The third millennium started January 1, 2001.
millisecondsThe seconds field, including fractional parts, multiplied by 1000.
minuteThe minutes field (0–59).
monthFor
timestampvalues, the number of the month within the year (1–12). Forintervalvalues, the number of months, modulo 12 (0–11).quarterThe quarter of the year (1–4) that the date is in.
secondThe seconds field, including fractional parts (0–59; can be 60 on leap seconds).
timezoneThe time zone offset from UTC, measured in seconds. Positive values correspond to time zones east of UTC, and negative values correspond to zones west of UTC.
timezone_hourThe hour part of the time zone offset.
timezone_minuteThe minute part of the time zone offset.
weekThe number of the ISO 8601 week-numbering week of the year. ISO weeks start on Mondays, and the first week of a year contains January 4 of that year. For example, the first Thursday of a year is in week 1 of that year. In the ISO week-numbering system, early January dates can fall in the 52nd or 53rd week of the previous year, and late December dates can fall in the first week of the next year. For example,
2005-01-01is part of the 53rd week of 2004,2006-01-01is part of the 52nd week of 2005, and2012-12-31is part of the first week of 2013. Use theisoyearfield together withweekto get consistent results.yearThe year field. There's no
0 AD, so subtractBCyears fromADyears with care.