Date format option?

Is there a date format option? There is a date.handler but what I ask for is something to switch from Y/m/d to like Y-m-d, H:i.

If there is no option I think it could be a nice addition. When making plugin that use a date/time it can be different in different countries. Another reason is that we may perfer another format. A global option would mean that all plugins could pick it up and display it as the user wants. The alternative is for every plugin to roll out their own option for it.

You mean change the way the data is stored in the text file? Because in a template, you can display the date in whatever way you want:

echo $page->date('Y-m-d, H:i);

Or do you mean how it is displayed in the Panel?

Yeah, I mean kind of like that but not bound to a page object.

Here is a microteaser of my latest plugin:


I present a date of a file. I could use my own fancy date format, or I could try to inherit the Kirby options as far as possible. I do the latter.

Right now the code for it looks like this (work in progress):

private function modified($filepath) {
        global $kirby;
        $format = $kirby->option('date.handler') == 'strftime' ? '%Y/%m/%d' : 'Y/m/d';
        return f::modified($filepath, $format, $kirby->options['date.handler']);

I can get the date.handler by what the user wants but not the format, because there is no such option that I’m aware of.

Hm, what would you do with such an option in a multi-lang environment? Maybe something like that could be part of the language setup in a future version, but right now, you would have to set this option as an array with an entry for each language :thinking:.

I can admit that I did not think about multi lang enviroments. :confused:

Maybe l::get('date.format', $format) for each language and a fallback to a c::get('date.format', $format) option when l::get is missing and on single lang installations?

@jenstornell I’m going to mark this as a suggestion here, feel free to create a feature request issue on GitHub, though. For Kirby itself such a setting is not really useful, because a default date format is not needed, but I see your use case.

1 Like