Skip to Main Content
Close Menu

Updating deprecated format_date() calls in Drupal 8


This covers only the most common use cases.





A little more information

If you are using other arguments

The order of arguments is consistent in the new service.


format_date(time(), 'custom', 'Y M D', 'America/Los_Angeles', 'en-us');


\Drupal::service('date.formatter')->format(time(), 'custom', 'Y M D', 'America/Los_Angeles', 'en-us');

More examples

We have a set of examples as part of the Drupal Rector rector_examples module. See

Automating updates with Drupal Rector

Drupal Rector is an open source tool built using Rector which can help automate this deprecation as well as other common deprecations.

For more information, see

What is covered by the rector

Drupal Rector currently replaces static calls to format_date() as shown above.

Improvement opportunities

Drupal Rector does not inject the date.formatter service into classes.

Deprecation background

format_date() used a global method call rather than a service, making unit testing more difficult.


The Drupal change record for this deprecation is available at

Credits and thank yous

Thank you to Dan Montgomery for leading Drupal Rector development to support this deprecation.

Thank you to for sponsoring this development.

Let’s work together.

Have an exceptional idea? Let's talk and see how we can help.
Contact Us