dataengref migrate

Home / SQL Server

SQL Server DATEDIFF in Snowflake, Databricks and BigQuery

The name survives in all three targets, but the results do not always match. SQL Server and Snowflake count unit boundaries crossed. Databricks counts whole elapsed units. BigQuery DATE_DIFF puts the end date first.

SQL Server function: DATEDIFF(datepart, startdate, enddate) · SQL Server docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeSame nameDATEDIFF(date_or_time_part, expr1, expr2)Same argument order and the same boundary counting as SQL Server: DATEDIFF(year, '2024-12-31', '2025-01-01') returns 1.Snowflake docs
DatabricksSame namedatediff(unit, start, end)Synonym of timestampdiff (Databricks Runtime 10.4 LTS and above). Counts whole elapsed units: one month has passed only when the day and time reach the start value. The two-argument datediff(endDate, startDate) form returns days and takes the end date first.Databricks docs
BigQueryRewriteDATE_DIFF(end_date, start_date, granularity)End date first. Counts unit boundaries, like SQL Server. Use DATETIME_DIFF or TIMESTAMP_DIFF for other types.BigQuery docs

Behavior differences to check

Databricks

BigQuery

Examples

Days between order and shipment

SQL Server
SELECT order_id, DATEDIFF(day, ordered_at, shipped_at) AS days_to_ship FROM orders;
Snowflake
SELECT order_id, DATEDIFF(day, ordered_at, shipped_at) AS days_to_ship FROM orders;
Databricks
SELECT order_id, datediff(DAY, ordered_at, shipped_at) AS days_to_ship FROM orders;
BigQuery
SELECT order_id, DATE_DIFF(DATE(shipped_at), DATE(ordered_at), DAY) AS days_to_ship FROM orders;

Other SQL Server functions

Last checked: · Paste a whole query into the SQL checker to find every function that needs a change.