We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

There are any date related wrappers in Phalcon?

Date wrappers would be really useful to help dealing with date outputs and calculations, example:

$this->date->today('Y-m-d'); // 2014-09-15
$this->date->today('Y-m-d','-1'); // 2014-09-14

$this->date->thisMonth('F') // September
$this->date->thisMonth('F','-1') // August

// ... etc

And there could be a DI setting to the default locale so you could define it "globally" on your project.

Would be really useful. There is something related in Phalcon already?



98.9k
Accepted
answer

You can use the built-in PHP datetime:

<?php

$d = new \DateTime();
$d->modify('-1 days');
echo $d->format('Y-m-d'); // 2014-09-14

$d = new \DateTime();
echo $d->format('F'); // September

$d->modify('-1 month');
echo $d->format('F'); // August

// ... etc

https://php.net/manual/en/class.datetime.php