DATEDIFF calculates the difference between two dates or timestamps using a specified date unit. Exact syntax and behavior vary by database system.
Date differences are essential for calculating durations, aging, turnaround time, employee tenure, and business intervals.
Calculate the number of days between an order date and delivery date.
SELECT
OrderID,
DATEDIFF(day, OrderDate, DeliveryDate) AS DeliveryDays
FROM Orders;
DATEDIFF is widely used for SLA monitoring, customer aging, employee tenure, delivery analysis, and operational reporting.
- DATEDIFF calculates date differences.
- A date unit is commonly specified.
- It is useful for duration analysis.
- Syntax varies significantly by database.
- It can support SLA and aging calculations.
What does DATEDIFF do?
DATEDIFF calculates the difference between two dates using a specified date or time unit.
Where is DATEDIFF useful for a Data Analyst?
It is useful for aging, turnaround time, SLA monitoring, delivery duration, and employee tenure analysis.