SQL • LESSON 35
DATEDIFF
Learn how to calculate the number of days between two dates.
🟠 Intermediate⏱ 3 Minutes⭐ 540 XP
🤔 THE QUESTION
How can we find how many days an employee has been working?
💡 WHAT IS IT?
DATEDIFF calculates the difference between two dates, allowing you to measure the number of days between them.
🎯 WHAT IS IT USED FOR?
It is useful for calculating employee tenure, order age, delivery delays, subscription duration, retention periods, and other date-based metrics.
💻 EXAMPLE
SELECT
name,
DATEDIFF(
CURRENT_DATE,
join_date
) AS days_worked
FROM employees;Mission Brief
Practice calculating the number of days between an employee's joining date and today.
Objectives
- ✓ DATEDIFF
- ✓ CURRENT_DATE
- ✓ Date difference
- ✓ Date calculations
- ✓ Column aliases