Reputation: 79
I have read a csv file and made a dataframe where timestamp column is in format "11/12/2020 3:01".
How do I convert this into "yyyy-mm-dd hh:mm:ss.ssssss" format for the data of that particular timestamp column?
Upvotes: 0
Views: 302
Reputation: 42422
import org.apache.spark.sql.functions._
df.withColumn("timestamp_col",
date_format(
unix_timestamp($"timestamp_col", "dd/MM/yyyy h:mm").cast("timestamp"),
"yyyy-MM-dd hh:mm:ss.SSSSSS"
)
)
Upvotes: 3
Reputation: 1
watch for .strftime in the documentation https://docs.python.org/3/library/datetime.html
timestamp.strftime("%d.%m.%Y")
Upvotes: 0