Skip to main content
SQL โ€ข LESSON 35

DATEDIFF

How can we measure the duration or difference between two dates in days?

Intermediateโฑ 3 Minutesโญ 540 XP
๐Ÿค” THE QUESTION

How can we measure the duration or difference between two dates in days?

๐Ÿ’ก WHAT IS IT?

DATEDIFF calculates the count of interval units between two date timestamps.

๐ŸŽฏ WHAT IS IT USED FOR?

Customer retention duration, employee tenure, ticket resolution time, shipping delays.

๐Ÿ’ป EXAMPLE
SELECT
name,
DATEDIFF(
  CURRENT_DATE,
  join_date
) AS days_worked
FROM employees;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for DATEDIFF.

  • โœ“ DATEDIFF
  • โœ“ Date difference
  • โœ“ Tenure calculations
  • โœ“ Analytics