function format_date

Same name and namespace in other branches
  1. 7.x includes/ \format_date()

Formats a date, using a date type or a custom date format string.


$timestamp: A UNIX timestamp to format.

$type: (optional) The format to use, one of:

  • One of the built-in formats: 'short', 'medium', 'long', 'html_datetime', 'html_date', 'html_time', 'html_yearless_date', 'html_week', 'html_month', 'html_year'.
  • The name of a date type defined by a date format config entity.
  • The machine name of an administrator-defined date format.
  • 'custom', to use $format.

Defaults to 'medium'.

$format: (optional) If $type is 'custom', a PHP date format string suitable for input to date(). Use a backslash to escape ordinary text, so it does not get interpreted as date format characters.

$timezone: (optional) Time zone identifier, as described at Defaults to the time zone used to display the page.

$langcode: (optional) Language code to translate to. Defaults to the language used to display the page.

Return value

A translated date string in the requested format.


in drupal:8.0.0 and is removed from drupal:9.0.0. Use \Drupal::service('date.formatter')->format().

See also


Related topics

1 call to format_date()
LegacyFunctionsTest::testFormatDate in core/tests/Drupal/KernelTests/Core/Common/LegacyFunctionsTest.php
Tests format_date().
3 string references to 'format_date'
DateField::defineValueProcessPipeline in core/modules/datetime/src/Plugin/migrate/field/DateField.php
Apply any custom processing to the field bundle migrations.
DateField::defineValueProcessPipeline in core/modules/datetime/src/Plugin/migrate/field/d6/DateField.php
Apply any custom processing to the field bundle migrations.
TwigExtension::getFilters in core/lib/Drupal/Core/Template/TwigExtension.php


core/includes/, line 332


function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
    @trigger_error("format_date() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \\Drupal::service('date.formatter')->format() instead. See", E_USER_DEPRECATED);
    return \Drupal::service('date.formatter')->format($timestamp, $type, $format, $timezone, $langcode);

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.