Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyspark convert dataframe column from timestamp to string of "YYYY-MM-DD" format

In pyspark is there a way to convert a dataframe column of timestamp datatype to a string of format 'YYYY-MM-DD' format?

like image 791
Partha Sarkar Avatar asked Feb 21 '18 16:02

Partha Sarkar


1 Answers

You can use date_format function as below

from pyspark.sql.functions import date_format

df.withColumn("dateColumn",  date_format(col("vacationdate"), "yyyy-MM-dd"))

Hope this helps!

like image 145
koiralo Avatar answered Sep 24 '22 01:09

koiralo