I have a column YDate
in the form yyyy-MM-dd HH:mm:ss
(timestamp type) but would like to convert it to dd/MM/yyyy
.
I tried that;
df = df.withColumn('YDate',F.to_date(F.col('YDate'),'dd/MM/yyyy'))
but get yyyy-MM-dd
.
How can I effectively do this.
Use date_format
instead:
df = df.withColumn('YDate',F.date_format(F.col('YDate'),'dd/MM/yyyy'))
to_date
converts from the given format, while date_format
converts into the given format.