I have a timestamp string with microseconds as follows:
+-------------------------+
|Time |
+-------------------------+
|22-10-2019 09:41:24.87816|
|22-10-2019 09:41:24.87818|
|22-10-2019 09:41:24.87820|
|22-10-2019 09:41:24.87821|
+-------------------------+
I want to convert it to TimestampType(). For example, "22-10-2019 09:41:24.87816" should be 1571737284.87816.
I've tried this:
df= df.withColumn("timestamp", to_timestamp("Time", format="dd-MM-yyyy HH:mm:ss.SSSSS"))
and this:
df= df.withColumn("timestamp", col("Time").cast(TimestampType()))
but both return nulls. What am I doing wrong??
I could create a UDF with datetime.strptime() but that would be too slow. Shouldn't to_timestamp() just work?