SQL Flow Field Guide

DATEDIFF

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

date/time arithmetic, parts, construction or truncation

What changes

Input
date/time arguments
Output or change
date/time or integer value
Return type
int

Syntax at a glance

DATEDIFF ( datepart , startdate , enddate )

Work example

Count datepart boundaries crossed between two timestamps.

Choose the smallest datepart that matches the question and test values around a boundary.

Check your work DATEDIFF counts boundaries crossed, not elapsed whole units.

Practice SQL

Open in SQL Flow
SELECT DATEDIFF(day, CONVERT(date, '2026-04-05'), CONVERT(date, '2026-04-06')) AS day_boundaries;

Open Microsoft Learn for full syntax, permissions, and details for your version.