$file->date($format = null, $field = 'date')
Returns a unix timestamp or formatted date string from the file's meta date field or any other field containing a parsable date
-
$format (string)
Date format -
$field (string)
Field from the meta file -
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="<?= $file->date('c') ?>">
<?= $file->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="<?= $file->date('c', 'createdAt') ?>">
<?= $file->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', $file->date()) ?>
<?= strftime('%d/%m/%Y', $file->date(null, 'createdAt')) ?>