Convert pyspark string to date format

后端 未结 6 1822
礼貌的吻别
礼貌的吻别 2020-11-22 05:21

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.

I tried:

6条回答
  •  不要未来只要你来
    2020-11-22 06:07

    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|  
    +-------------------+  
    

提交回复
热议问题