Increment a date by one day

Hi,

This is probably simple but I can’t seem to work it out.

I have a date field in the panel, and want to output the entered date plus one day.

I have tried this:

<?= $event->endDate()->add('1d')->toDate('Ymd') ?>

But that is still outputting the original date. I have looked in the docs, and found this: $date->add() | Kirby CMS which is where I got the add from, and I think my formatting for DateInterval is correct.

If someone could offer some advice that would be great. Thanks!

This fails because

So to make this work:

$date = new Kirby\Toolkit\Date($event->endDate()->toDate());

dump($date->add(new DateInterval('P1D')));

Wow - I was miles away! Haha thanks for your patience @texnixe I will give that a spin

For future reference I did this using the above technique in a field method, details below:

site/plugins/field-methods/index.php

<?php

use Kirby\Toolkit\Date;

Kirby::plugin('mhd/field-methods', [
    'fieldMethods' => [
        'oneDayLater' => function ($field) {
          $date = new Kirby\Toolkit\Date($field->toDate());
          $newDate = $date->add(new DateInterval('P1D'))->format('Ymd');
          return $newDate;
        },
    ]
]);

?>