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. EXTRACT and date_part support the same field options. For valid options, see Fields.
  • <source>: The value to extract the field from. Must be an expression of type date, timestamp, timestamptz, time, or interval. These functions cast values of type date to timestamp.
  • <fiscal_option>: A fiscal calendar option that defines the start date of the fiscal calendar. <source> must be of type date, timestamp, or timestamptz, and <field> must be fiscal_week, fiscal_month, fiscal_quarter, or fiscal_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 type date, timestamp, or timestamptz, and <field> must be localized_week. See Localized Week Options.

The result type of EXTRACT depends on the field:

  • numeric(8,6) for the field second
  • numeric(18,6) for the field epoch
  • integer for any other field

The result type of date_part is always double precision, independent of the selected field.

  • Data 360 Apps: EXTRACT and DATE_PART don’t support the timezone, timezone_hour, timezone_minute, fiscal_month, fiscal_quarter, fiscal_week, or fiscal_year fields. DATE_PART also doesn’t support the 'ago', 'julian', 'timezonehour', or 'timezoneminute' field values.
  • Data 360 Apps: Extracting localized_week is supported for date and timestamptz inputs, but not for timestamp inputs.
century

The century. The first century starts at 0001-01-01 00:00:00 AD. There's no century number 0.

day

For timestamp values, the day of the month (1–31). For interval values, the number of days.

decade

The year field divided by 10.

dow

The day of the week as Sunday (0) to Saturday (6).

doy

The day of the year (1–365/366).

epoch

For timestamp with time zone values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative). For date and timestamp values, the number of seconds since 1970-01-01 00:00:00 local time. For interval values, the total number of seconds in the interval.

To convert an epoch value back to a timestamp, use to_timestamp.

fiscal_month

The month within the fiscal year (1–12).

fiscal_quarter

The quarter within the fiscal year (1–4).

fiscal_week

The week within the fiscal year (1–54).

fiscal_year

The fiscal year.

hour

The hour field (0–23).

isodow

The day of the week as Monday (1) to Sunday (7). This is identical to dow except for Sunday.

isoyear

The 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 week field for more information.

localized_week

The week within the year with a custom start date, determined by the first_day_of_localized_week and minimal_days_in_localized_first_week parameters. See Localized Week Options for a detailed explanation and examples.

microseconds

The seconds field, including fractional parts, multiplied by 1,000,000.

millennium

The millennium. Years in the 1900s are in the second millennium. The third millennium started January 1, 2001.

milliseconds

The seconds field, including fractional parts, multiplied by 1000.

minute

The minutes field (0–59).

month

For timestamp values, the number of the month within the year (1–12). For interval values, the number of months, modulo 12 (0–11).

quarter

The quarter of the year (1–4) that the date is in.

second

The seconds field, including fractional parts (0–59; can be 60 on leap seconds).

timezone

The 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_hour

The hour part of the time zone offset.

timezone_minute

The minute part of the time zone offset.

week

The 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-01 is part of the 53rd week of 2004, 2006-01-01 is part of the 52nd week of 2005, and 2012-12-31 is part of the first week of 2013. Use the isoyear field together with week to get consistent results.

year

The year field. There's no 0 AD, so subtract BC years from AD years with care.