EXTRACT / DATE_PART
Feb 23, 2026
·
5
min read
Category: Date/Time Functions
Platform Support:
✅ Snowflake | ✅ BigQuery | ✅ Databricks
Description
Extract specific components (year, month, day, hour, etc.) from date or timestamp values. EXTRACT is standard SQL, DATE_PART is an alternative function. Essential for date analysis, filtering, and grouping by time components.
Syntax
EXTRACT (Standard SQL):
DATE_PART (Alternative):
Available Parts:
YEAR, QUARTER, MONTH, WEEK, DAY
HOUR, MINUTE, SECOND, MILLISECOND
DAYOFWEEK, DAYOFYEAR, WEEKOFYEAR
EPOCH (seconds since 1970-01-01)
Platform-Specific Notes
Snowflake:
Both EXTRACT and DATE_PART supported
Additional: YEAROFWEEK, YEAROFWEEKISO
EPOCH for Unix timestamp
Rich set of date parts
BigQuery:
EXTRACT preferred
Additional: ISOWEEK, ISOYEAR
DATETIME parts (DATE, TIME)
WEEK starts Sunday by default
Databricks:
Both EXTRACT and DATE_PART
Standard Spark SQL functions
Also: YEAR(), MONTH(), DAY() functions
Compatible with Hive
Example 1: Extract Date Components
All Platforms:
Sample Data (orders table):
order_id | order_date |
|---|---|
101 | 2024-01-15 |
102 | 2024-02-20 |
103 | 2024-03-10 |
104 | 2024-06-25 |
105 | 2024-12-31 |
Result:
order_date | year | quarter | month | day | day_of_week | day_of_year | week_of_year |
|---|---|---|---|---|---|---|---|
2024-01-15 | 2024 | 1 | 1 | 15 | 2 | 15 | 3 |
2024-02-20 | 2024 | 1 | 2 | 20 | 3 | 51 | 8 |
2024-03-10 | 2024 | 1 | 3 | 10 | 1 | 70 | 10 |
2024-06-25 | 2024 | 2 | 6 | 25 | 3 | 177 | 26 |
2024-12-31 | 2024 | 4 | 12 | 31 | 3 | 366 | 53 |
Example 2: Extract Time Components
All Platforms:
Sample Data (events table):
event_id | event_timestamp |
|---|---|
1 | 2024-01-15 09:30:45 |
2 | 2024-01-15 14:15:30 |
3 | 2024-01-15 18:45:00 |
Result:
event_timestamp | hour | minute | second | time_hhmm |
|---|---|---|---|---|
2024-01-15 09:30:45 | 9 | 30 | 45 | 09:30 |
2024-01-15 14:15:30 | 14 | 15 | 30 | 14:15 |
2024-01-15 18:45:00 | 18 | 45 | 0 | 18:45 |
Example 3: Group By Date Components
All Platforms:
Result:
year | month | order_count | monthly_revenue | avg_order_value |
|---|---|---|---|---|
2024 | 1 | 145 | 42500.00 | 293.10 |
2024 | 2 | 168 | 51200.00 | 304.76 |
2024 | 3 | 152 | 47800.00 | 314.47 |
Example 4: Day of Week Analysis
All Platforms:
Result:
day_of_week_num | day_name | order_count | avg_order_value |
|---|---|---|---|
1 | Sunday | 85 | 312.45 |
2 | Monday | 142 | 285.30 |
3 | Tuesday | 156 | 298.75 |
4 | Wednesday | 148 | 305.20 |
5 | Thursday | 153 | 295.80 |
6 | Friday | 189 | 325.50 |
7 | Saturday | 127 | 340.15 |
Example 5: Hour of Day Pattern Analysis
All Platforms:
Result:
hour | time_of_day | event_count | unique_users |
|---|---|---|---|
0 | Night | 125 | 45 |
1 | Night | 85 | 32 |
... | ... | ... | ... |
9 | Morning | 1250 | 520 |
14 | Afternoon | 1580 | 680 |
20 | Evening | 980 | 425 |
Example 6: Unix Timestamp (EPOCH)
Snowflake/Databricks:
BigQuery:
DATE_PART vs EXTRACT
Both are equivalent:
Platform-Specific Alternatives
Databricks also supports:
Snowflake also supports:
Common Date Parts Reference
Part | Description | Example Value |
|---|---|---|
YEAR | 4-digit year | 2024 |
QUARTER | Quarter (1-4) | 1 |
MONTH | Month (1-12) | 3 |
WEEK | Week of year (1-53) | 12 |
DAY | Day of month (1-31) | 15 |
DAYOFWEEK | Day of week (1-7) | 2 (Monday) |
DAYOFYEAR | Day of year (1-366) | 75 |
HOUR | Hour (0-23) | 14 |
MINUTE | Minute (0-59) | 30 |
SECOND | Second (0-59) | 45 |
EPOCH | Seconds since 1970-01-01 | 1705329000 |
Common Use Cases
Temporal grouping: Aggregate by month, quarter, year
Pattern analysis: Day of week, hour of day trends
Filtering: Find records from specific months or hours
Business logic: Fiscal year calculations
Reporting: Year-over-year comparisons
Scheduling: Route based on time of day
Performance Tips
Avoid EXTRACT in WHERE: Can prevent index use
Create computed columns: For frequently extracted parts
Use DATE_TRUNC for ranges: More efficient than EXTRACT
Index extracted values: If used frequently in WHERE
Materialize common extractions: In views or tables
Best Practices
Use consistent timezone: Especially with timestamps
Document week start day: Different platforms may vary
Handle NULL dates: Use COALESCE if needed
Use appropriate granularity: Don't extract more than needed
Consider fiscal vs calendar: For business reporting
Test edge cases: Month boundaries, leap years, DST
Use DATE_TRUNC for grouping: Often more efficient





