Suggestion for a localized date output modifier

For a current project I need german date outputs (with day names). In 2007 @jako created a snippet with the deprecated strftime function (https://www.partout.info/blog/deutsches-datum.html).

There are longer discussions in this community about new date formatting options, for instance here: What's happening with the strftime() and date() output modifiers? - #13 by bobray

I’m not a programmer but I tried to create an output modifier for german dates. Maybe it’s helpful for others? This is the snippet code:

<?php
/*
 * description: returns german date compatible to PHP 8.1 and above
 * usage: [+string:date_ger=`format`+]
 */
$date = strtotime($input);
$format = (strlen($options) > 0) ? $options : 'cccc, d. MMMM YYYY';

$fmt = datefmt_create(
    'de_DE',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'Europe/Berlin',
    IntlDateFormatter::GREGORIAN,
    $format
);

$output =  datefmt_format($fmt, $date);
return $output;

And here you will find patterns to format the desired date: Formatting Dates and Times | ICU Documentation

Some examples:

  • ccc., dd.MM.yy => Mo., 06.02.23
  • cccc, d. MMMM YYYY => Montag, 6. Februar 2023
  • cccc, d. MMMM YYYY, HH:mm => Montag, 6. Februar 2023, 15:30
2 Likes

To format a date on base of a locale with MODX Revolution, you just have to set the MODX system setting locale to ‘de_DE.utf8’. You don’t need an own date_ger output filter.

The MODX core will hopefully use php-8.1-strftime.php or something similar for BC in PHP 8.2+

Thanks for your advice. I hope it will all work like expected in the future. If not, I have this snippet :wink: