0

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?

sparc
  • 345
  • 1
  • 2
  • 13

1 Answers1

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