DATE_PART()

All functions > DATE AND TIME > DATE_PART()

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

Signatures

Returns: The extracted component as BIGINT

DATE_PART(timestamp: T, unit: VARCHAR) → BIGINT
sql
ParameterTypeRequiredDescription
timestampTYesA DATE, TIMESTAMP, or INTERVAL value
unitVARCHARYesThe time unit to extract (e.g., 'year', 'month', 'day') compile-time

With:

  • T : Custom types: DATE | TIMESTAMP | INTERVAL

Notes

  • Extracts a specific component from a date/time value
  • Canonical spelling. YEAR(d), MONTH(d), DAY(d), HOUR/MINUTE/SECOND/WEEK/QUARTER, EXTRACT(YEAR FROM d), and EXTRACT_FROM_DATE are permissive and FORMAT (FIX) rewrites them here
  • Unit must be a lowercase singular string literal in strict mode: DATE_PART(d, 'year')
  • Common units: 'year', 'month', 'day', 'hour', 'minute', 'second'
  • Also supports: 'dow' (day of week), 'doy' (day of year), 'week', 'quarter'
  • Works with DATE, TIMESTAMP, and INTERVAL types
  • Day of week: 1 = Monday, 7 = Sunday
  • Date EXTRACT(UNIT FROM ts) is this function. Row/array field projection is row[field], not EXTRACT

Aliases

  • EXTRACT_FROM_DATE

Examples

FeatureQL
RETURN
    -- Extract year component
    f1 := DATE_PART(FROM_ISO8601_TIMESTAMP('2024-03-15T10:30:45'), 'year'),
    -- Extract month component
    f2 := DATE_PART(FROM_ISO8601_TIMESTAMP('2024-03-15T10:30:45'), 'month'),
    -- Extract day component
    f3 := DATE_PART(FROM_ISO8601_TIMESTAMP('2024-03-15T10:30:45'), 'day'),
    -- Extract hour component
    f4 := DATE_PART(FROM_ISO8601_TIMESTAMP('2024-03-15T10:30:45'), 'hour')
;
Result
f1 BIGINTf2 BIGINTf3 BIGINTf4 BIGINT
202431510