$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)


with date field

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

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

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="<?php echo $page->date('c', 'createdAt') ?>">
  <?php echo $page->date('d/m/Y', 'createdAt') ?>

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.

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