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
Parameter | Type | Required | Description |
---|---|---|---|
timestamp | DATE | Yes | A DATE, TIMESTAMP, or INTERVAL value |
unit | VARCHAR | Yes | The 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