date_format function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Converts a timestamp to a string in the format fmt.

Syntax

date_format(expr, fmt)

Arguments

  • expr: A DATE, TIMESTAMP, or a STRING in a valid datetime format.
  • fmt: A STRING expression describing the desired format.

Returns

A STRING.

See Datetime patterns for details on valid formats.

Examples

> SELECT date_format('2016-04-08', 'y');
 2016