I have a column which is a string in dd/MM/yyyy hh:mm:ss format to timestamp like yyyy-MM-dd hh:mm:ss in pyspark?
Asked
Active
Viewed 250 times
1 Answers
0
df = spark.createDataFrame(
[('10/08/2022 10:29:19', )],
schema=['timestamp_str']
)
df.show(3, False)
+-------------------+
|timestamp_str |
+-------------------+
|10/08/2022 10:29:19|
+-------------------+
You can use .to_timestamp()
:
df.withColumn('timestamp_str', func.to_timestamp(func.col('timestamp_str'), 'dd/MM/yyyy HH:mm:ss')).show(100, False)
+-------------------+
|timestamp_str |
+-------------------+
|2022-08-10 10:29:19|
+-------------------+

Jonathan Lam
- 1,761
- 2
- 8
- 17