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
| Parameter | Type | Required | Description |
|---|---|---|---|
timestamp | T | Yes | A DATE, TIMESTAMP, or INTERVAL value |
unit | VARCHAR | Yes | The 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), andEXTRACT_FROM_DATEare permissive andFORMAT (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 isrow[field], notEXTRACT
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 BIGINT | f2 BIGINT | f3 BIGINT | f4 BIGINT |
|---|---|---|---|
| 2024 | 3 | 15 | 10 |
On this page