$page->date($format = null, $field = 'date')

Returns a unix timestamp or formatted date string from the page's date field or any other field containing a parsable date

  • $format (string)
    A date format
  • $field (string)
    The name of the date field if different from "date".
  • return (integer | string)

Example

with date field

By default the date method assumes that there's a date field in the text file.

<time datetime="<?= $page->date('c') ?>">
  <?= $page->date('d/m/Y') ?>
</time>

with a custom field

If you want to use the date method with a custom field, you can pass the name of the field as second parameter

<time datetime="<?= $page->date('c', 'createdAt') ?>">
  <?= $page->date('d/m/Y', 'createdAt') ?>
</time>

working with the timestamp

By default the date method will return the Unix timestamp. You can use that to make date calculations or format dates with strftime.

<?= strftime('%d/%m/%Y', $page->date()) ?>
<?= strftime('%d/%m/%Y', $page->date(null, 'createdAt')) ?>

Is something missing or incorrect? Edit this page on Github…