Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



83.4k
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

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