to_date
function
October 10, 2023
Applies to: Databricks SQL
Databricks Runtime
Returns expr
cast to a date using an optional formatting.
In this article:
Arguments
expr
: A STRING expression representing a date.fmt: An optional format STRING expression.
Returns
A DATE.
If fmt
is supplied, it must conform with Datetime patterns.
If fmt
is not supplied, the function is a synonym for cast(expr AS DATE)
.
If fmt
is malformed or its application does not result in a well formed date, the function raises an error.
Note
In Databricks Runtime, if spark.sql.ansi.enabled is false
, the function returns NULL
instead of an error for malformed dates.