Panel field date only saving a timestamp with the name "date"

When giving a date field a different name than “date”, the saved value does not get stored as timestamp, which makes handling dates in the the templates very inconsistent.

date:
  label: Date
  type: date

<?= $page->date(); ?>

Outputs: 1527379200

date_custom:
  label: Date
  type: date

<?= $page->date_custom(); ?>

Outputs: 2018-05-27

The value that is stored in a date field is the same as the one stored in a custom date field. But because the date method is a special method, it returns a Unix timestamp while a custom date field does not. To output a Unix timestamp from a custom date field, you can call the date method like this:

<?= $page->date(null, 'date_custom'); ?>

To output a custom date format:

<?= $page->date('Y-m-d', 'date_custom'); ?>
1 Like