How can I use "strftime" to render e.g. "1.1.2021"?

I’ve set the date handler in the site/config/config.php to strftime:

<?php
return [
    'date'  => [
        'handler' => 'strftime'
    ]
];?>

as I want the day and month to be displayed as a single digit number like “1.1.2021”. But it seems not to work yet.

I render it like this:

<?= $event->from()->toDate('%e.%m.%Y') ?>

Additionally I can’t find the syntax for the single digit month here: PHP: strftime - Manual

What’s wrong about my code? :confused:

It doesn’t seem to be supported. Why do you want to use the strftime handler if you only need digits?

And what does it mean that it doesn’t work? Do you happen to have multiple return statements in your config?

1 Like

On this page I read that I have to use it in order to be able to render it this way in my template: Working with dates | Kirby CMS

Is there an easier way to remove the “0” before a day?

You’re right, I had another return statement in my config and just solved the problem by putting it underneath it.

<?php
return [
    'debug'  => true,
    'date'  => [
        'handler' => 'strftime'
    ]
]; ?>

Did not know how to handle with more than one return statement :slight_smile:

Using the strftime handler makes sense if you want to use localized month and day names, for dates only consisting of numbers, it is not necessary.

Okay, but I am only aware of changing the format in the blueprint file (D.M.YYYY) to be displayed in the kirby panel.
Is there a way to render it the same way but without “strftime”?

You can pass the format to the toDate() function like this (with the standard date handler),e.g.

<?= $event->from()->toDate('j.n.Y') ?>

All available formats can be found here: PHP: DateTime::format - Manual

ah okay, thanks… :slight_smile: