I have a dataset like the below:
df = spark.sql("select '210927' as t_date")
Now, I want to convert it to '27-09-2021'
. Below is my code along with the error:
>>> df = df.withColumn("modifiedDate",datetime.strptime("t_date", "%y%m%d").strftime('%d-%m-%Y'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/_strptime.py", line 568, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "/usr/lib/python3.8/_strptime.py", line 349, in _strptime
raise ValueError("time data %r does not match format %r" %
ValueError: time data 't_date' does not match format '%y%m%d'
I tried several examples from SO and this link but didn't work. I am using Python
with Pyspark