Reference

Guide

$field->toDate()

Converts the field value to a timestamp or a formatted date

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

Parameters

Name Type Default Description
$format string null

PHP date formatting string

$fallback string null

Fallback string for strtotime (since 3.2)

Return type

string|int

Examples

To a Unix timestamp

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

To a formatted date string

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

With fallback parameter

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

Check out PHP's date function docs for all available formatting options: http://php.net/manual/en/function.date.php

Source code

kirby/config/methods.php#L98