PySpark SQL Functions | to_date method
Start your free 7-days trial now!
PySpark SQL Functions'
to_date() method converts date strings to date types.
The date string column.
The format of the date string.
A PySpark Column.
Consider the following PySpark DataFrame with some date strings:
Converting date strings to date type in PySpark
To convert date strings in the
birthday column to actual
date type, use
to_date(~) and specify the pattern of the date string:
withColumn(~) method is used to update the
birthday column using the new column returned by
As another example, here's a PySpark DataFrame with slightly more complicated date strings:
Here, our date strings also contain hours, minutes and seconds.
To convert the
birthday column to
Here, notice how information about the hours, minutes and seconds unit have been lost during the type conversion.