pyspark.sql.functions.date_format(date, format)[source]

Converts a date/timestamp/string to a value of string in the format specified by the date format given by the second argument.

A pattern could be for instance dd.MM.yyyy and could return a string like ‘18.03.1993’. All pattern letters of datetime pattern. can be used.

New in version 1.5.0.


Whenever possible, use specialized functions like year.


>>> df = spark.createDataFrame([('2015-04-08',)], ['dt'])
>>>'dt', 'MM/dd/yyy').alias('date')).collect()