Creating a new date format in Drupal 9

I'm a little surprised that Drupal doesn't come with my favorite plain date formats by default.

I especially like and use dates without times - even for fields that store times.

Date formats are part of the Regional and language section of the Configuration features.

To create a custom date format:

Go to Configuration > Regional and language > Date and time formats

https://example.com/admin/config/regional/date-time

Click Add format

Enter a Format string to define your date.

some PHP date formats
Format string Result
F d, Y May 29, 2022
l, F d, Y Sunday, May 29, 2022
Y-m-d 2022-05-29
n/j/Y 5/9/2022

For that last format, I often prefer short dates without leading zeroes. Using n for the month and j for the day gives me that single-digit output.

 

Tags