MSSQLDate/Time FunctionsDATEDIFF
DATEADD

DATEDIFFDate/Time Functions

DATEDIFF_BIG

Returns the difference between two dates in the specified unit.

Syntax

DATEDIFF(unit, d1, d2)

Example

Enter values below to update the example in real time.

order_id
order_date
delivered_at
delivery_days
orders
-- 주문에서 배송까지 일수
SELECT order_id,
       DATEDIFF(DAY, order_date, delivered_at) AS delivery_days
FROM orders
WHERE delivered_at IS NOT NULL;