Beginner

267. EXTRACT Function

Learn how to extract individual components from dates and timestamps.

📘 Lesson 267 of 728 ⏱ 9 min 🎯 Intermediate

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.

SQL
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.

Have you finished this lesson?

Introduction to SQL – All Lessons