Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Applies to:
Databricks SQL
Databricks Runtime 17.2 and above
Returns expr cast to a date using optional formatting, or NULL if the cast fails.
Syntax
try_to_date(expr [, fmt] )
Arguments
expr: ASTRING,DATE, orTIMESTAMPexpression that represents a date.- fmt: An optional format
STRINGexpression.
Returns
A DATE.
If you omit fmt, the function is equivalent to try_cast(expr AS DATE).
If fmt is malformed, Azure Databricks raises INVALID_DATETIME_PATTERN. If expr cannot be parsed using fmt, the function returns NULL.
Common error conditions
Examples
> SELECT try_to_date('2016-12-31');
2016-12-31
> SELECT try_to_date('31/12/2016', 'dd/MM/yyyy');
2016-12-31
> SELECT try_to_date('2016-12-32', 'yyyy-MM-dd');
NULL