Working with dates
Any field in Kirby can be converted to a date if the content is parseable by PHP.
In your template …
As an argument you can pass any valid PHP date format string. If you don't pass an argument, the function will return a Unix timestamp, which you can use for more fancy PHP date calculation.
We suggest that you stick to the format YYYY-MM-DD HH:MM:SS
(i.e. 2018-11-21 11:22:33
). If you want to use another date format in your text files, read more about parseable date formats in PHP.
Article example
Custom date handler
PHP's date function is great, but if you work on multi-language sites and you need to translate dates, the IntlDateFormatter
PHP class provided through our intl
date handler is the way to go. You can change the date handler in your config.
If you change the date handler, you have to adjust existing date format strings in your templates. Find out more about ICU Date formats
In your template …
Instead of passing a format string, you can also pass an IntlDateFormatter
object as argument to the toDate()
method:
For details, see the IntlDateFormatter
PHP class