Extract YEAR, MONTH, and DAY from Dates in SQL
📖 Scenario: You work in a company database where customer orders are stored with full date and time stamps. You want to analyze orders by year, month, and day separately to understand seasonal trends.
🎯 Goal: Build a SQL query that extracts the YEAR, MONTH, and DAY from a date column called order_date in the orders table.
📋 What You'll Learn
Create a table called
orders with an order_id and order_date columnInsert three specific rows with exact
order_date valuesWrite a query that selects
order_id and extracts YEAR(order_date), MONTH(order_date), and DAY(order_date)Alias the extracted columns as
order_year, order_month, and order_day💡 Why This Matters
🌍 Real World
Extracting parts of dates is common in business reports, sales analysis, and time-based filtering.
💼 Career
Database developers and analysts often write queries to break down dates for trend analysis and reporting.
Progress0 / 4 steps