Convert pyspark string to date format

后端 未结 6 1735
礼貌的吻别
礼貌的吻别 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:15

    In the accepted answer's update you don't see the example for the to_date function, so another solution using it would be:

    from pyspark.sql import functions as F
    
    df = df.withColumn(
                'new_date',
                    F.to_date(
                        F.unix_timestamp('STRINGCOLUMN', 'MM-dd-yyyy').cast('timestamp')))
    

提交回复
热议问题