The EXTRACT function retrieves a specific date or time component such as YEAR, MONTH, DAY, HOUR, MINUTE, or SECOND from a date or timestamp.
Date components are essential for time-based analysis, reporting, grouping, and filtering.
Extract the month from an order date.
SELECT
OrderDate,
EXTRACT(MONTH FROM OrderDate) AS OrderMonth
FROM Orders;
EXTRACT is widely useful for monthly sales analysis, year-over-year reporting, trend analysis, and date-based segmentation.
- EXTRACT retrieves date components.
- It can return year, month, day, and time components.
- It is useful for analytical grouping.
- It is supported by many SQL systems.
- Syntax can vary slightly between databases.
What does EXTRACT do?
EXTRACT retrieves a specified component such as year, month, or day from a date or timestamp.
How can EXTRACT help a Data Analyst?
It allows dates to be broken into useful components for grouping, filtering, and trend analysis.