Best practice to handle time values?

In a model I compare two date values (one is the last update of the page, the other is stored “globally” in site->OffersdataLastupdate).


    dump($this->uid() . '.txt' . ' has been last modified on: ' . $this->modified('d/m/Y H:i'));
    dump('The structured data of ' . $this->uid() . ' has been last modified on: ' . gmdate("d/m/Y H:i", site()->OffersdataLastupdate()->toInt()));

OffersdataLastupdate is defined like this:

    'OffersdataLastupdate' => $newPage->modified()

Both have been updated at the same time but the value has a difference of two hours.
I guess one is UNIX time and the other is local time.


offers.txt has been last modified on: 21/04/2021 11:03
The structured data of offers has been last modified on: 21/04/2021 09:03

How can I save both in the UNIX format?

Is there a reason why you’re using gmdate() instead of simply date()?

By default, Kirby uses date() behind the scenes as its ‘date handler’ function. If you specifically want to do things like time-zone conversions or date localisation you may want to change your date handler to strftime(), as described here in the docs.

If you’re using the date() handler, the format string for the Unix timestamp is U - if I remember correctly… If you’re using the strftime() handler, the format string is %s.


site()->OffersdataLastupdate()->toDate('d/m/Y H:i')

instead of GMT

I’ve tried that before as well.
It results in:

01/01/1970 01:00

I wonder why you need to format those strings at all, instead of comparing the unix timestamps?

site()->OffersdataLastupdate()->toDate() // toDate without parameters returns UNIX timestamp



In the end I will compare UNIX time values only, but for testing purposes I wanna output it into a human readable format.

date("d/m/Y H:i", site()->OffersdataLastupdate()->toInt()))

instead of

gmdate("d/m/Y H:i", site()->OffersdataLastupdate()->toInt()))

was the solution.