In PySpark use date_format()
function to convert the DataFrame column from Date to String format. In this tutorial, we will show you a Spark SQL example of how to convert Date to String format using date_format()
function on DataFrame.
date_format()
– function formats Date to String format. This function supports all Java Date formats specified in DateTimeFormatter.
Following are Syntax and Examples of date_format() Function
The below code snippet takes the current system date from current_date()
and timestamp from the current_timestamp()
function and converts it to String format on DataFrame.
Output:
Alternatively, you can convert Data to String with SQL by using the same functions.
Complete Example
Conclusion
In this article, we have learned how to convert Date to String format using the Date function date_format()
.