I have a date pyspark dataframe with a string column in the format of MM-dd-yyyy and I am attempting to convert this into a date column.
MM-dd-yyyy
I tried:
Try this:
df = spark.createDataFrame([('2018-07-27 10:30:00',)], ['Date_col']) df.select(from_unixtime(unix_timestamp(df.Date_col, 'yyyy-MM-dd HH:mm:ss')).alias('dt_col')) df.show() +-------------------+ | Date_col| +-------------------+ |2018-07-27 10:30:00| +-------------------+