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.
This is a special version of try_to_date that performs the same operation, but returns a NULL value instead of raising an error if date cannot be created.
Syntax
from pyspark.sql import functions as dbf
dbf.try_to_date(col=<col>, format=<format>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
input column of values to convert. |
format |
literal string, optional |
format to use to convert date values. |
Returns
pyspark.sql.Column: date value as pyspark.sql.types.DateType type.
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([('1997-02-28',)], ['ts'])
df.select('*', dbf.try_to_date(df.ts)).show()
df.select('*', dbf.try_to_date('ts', 'yyyy-MM-dd')).show()
df = spark.createDataFrame([('foo',)], ['ts'])
df.select(dbf.try_to_date(df.ts)).show()