Beginner

218. Extracting Date Parts

Learn how to extract year, month, day, and other components from date values.

📘 Lesson 218 of 728 ⏱ 9 min 🎯 Intermediate

SQL provides functions such as EXTRACT or database-specific date functions to retrieve individual components such as year, month, day, hour, or minute from date and time values.

Business analysis frequently requires grouping and filtering data by year, month, quarter, or day.

Extract the year from an order date.

SQL
SELECT
    OrderID,
    EXTRACT(YEAR FROM OrderDate) AS OrderYear
FROM Orders;

Date-part extraction is used in sales trends, monthly reporting, financial analysis, seasonal analysis, and dashboard preparation.

  • Date parts can be extracted from date values.
  • Common parts include year, month, and day.
  • Syntax varies across database systems.
  • Date parts are useful for grouping.
  • They are common in reporting queries.
Why extract the year from a date?

It allows records to be grouped, filtered, or analyzed by year.

Does every database use EXTRACT?

No. Database systems may provide different functions for extracting date components.

Have you finished this lesson?

Introduction to SQL – All Lessons