EXTRACT_FROM_DATE

All functions > DATE_AND_TIME > EXTRACT_FROM_DATE

Returns the part of the given timestamp in the given unit.

Syntax

EXTRACT_FROM_DATE(timestamp, unit)
sql

Arguments

ParameterTypeRequiredDescription
timestampDATEYesA DATE, TIMESTAMP, or INTERVAL value
unitVARCHARYesThe time unit to extract (e.g., 'year', 'month', 'day')

Returns

The extracted component as BIGINT

Notes

  • Extracts a specific component from a date/time value
  • Common units: 'year', 'month', 'day', 'hour', 'minute', 'second'
  • Also supports: 'dow' (day of week), 'doy' (day of year), 'week'
  • Works with DATE, TIMESTAMP, and INTERVAL types
  • Day of week: 1 = Monday, 7 = Sunday
  • Useful for grouping by time components or filtering by date parts

Examples

Last update at: 2025/10/13 10:23:46