Skip to content

Kirby 4.2.0


Converts the field value to a timestamp or a formatted date

$field->toDate(IntlDateFormatter|string|null $format = null, ?string $fallback = null): string|int|null


Name Type Default Description
$format IntlDateFormatter|string|null null PHP date formatting string
$fallback string|null null Fallback string for strtotime

Return type



To a Unix timestamp

<?= $page->createdAt()->toDate() ?>

To a formatted date string

<?= $page->createdAt()->toDate('d.m.Y') ?>

With fallback parameter

<?= $page->createdAt()->toDate('d.m.Y', 'now') ?>

Check out PHP's date function docs for all available formatting options:

If you use the intl date handler for localized date strings, the format syntax is different:

The strftime date handler is deprecated as of PHP 8.1, and should not be used for new projects.