pyspark.sql.functions.date_format

pyspark.sql.functions.date_format(date: ColumnOrName, format: str) → pyspark.sql.column.Column[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.

Notes

Whenever possible, use specialized functions like year.

Examples

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