dataengref migrate

Home / SQL Server

SQL Server DATEPART in Snowflake, Databricks and BigQuery

Snowflake has DATE_PART, Databricks has date_part, and BigQuery uses EXTRACT(part FROM date). Weekday and week numbers are where results differ, because SQL Server depends on SET DATEFIRST and language settings.

SQL Server function: DATEPART(datepart, date) · SQL Server docs

Equivalents

TargetSupportSyntaxNotesSource
SnowflakeDifferent nameDATE_PART(date_or_time_part, expr)EXTRACT(part FROM expr) is equivalent. Returns NUMBER.Snowflake docs
DatabricksDifferent namedate_part(fieldStr, expr)Synonym of extract(field FROM expr). The field is a string such as 'YEAR' or 'DOW'.Databricks docs
BigQueryRewriteEXTRACT(part FROM date_expression)Parts are keywords: YEAR, QUARTER, MONTH, WEEK, DAY, DAYOFWEEK, DAYOFYEAR.BigQuery docs

Behavior differences to check

Examples

Orders per year and month

SQL Server
SELECT DATEPART(year, order_date) AS y, DATEPART(month, order_date) AS m, COUNT(*) FROM orders GROUP BY DATEPART(year, order_date), DATEPART(month, order_date);
Snowflake
SELECT DATE_PART(year, order_date) AS y, DATE_PART(month, order_date) AS m, COUNT(*) FROM orders GROUP BY 1, 2;
Databricks
SELECT date_part('YEAR', order_date) AS y, date_part('MONTH', order_date) AS m, COUNT(*) FROM orders GROUP BY 1, 2;
BigQuery
SELECT EXTRACT(YEAR FROM order_date) AS y, EXTRACT(MONTH FROM order_date) AS m, COUNT(*) FROM orders GROUP BY 1, 2;

Other SQL Server functions

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