Posts Tagged: DateTime

PHP Get the First of Next Month

While having fun with dates, I needed to get the timestamp for the first of the next month, here’s how I did it with PHP. strtotime(date(‘m’, strtotime(‘+1 month’)) . ‘/01/’ . date(‘Y’, strtotime(‘+1 month’))); I then used that to create a PHP DateTime object like this. $date = new DateTime(); $date->setTimestamp(strtotime(date(‘m’, strtotime(‘+1 month’)) . ‘/01/’… Read more »

Symfony Error: Call to a member function format() on string

This Symfony error tripped me up for a few minutes today, it’s not particularly obvious what it’s referring to. Error: Call to a member function format() on string In my case, I was setting a Doctrine entity field to a string when it should have been a DateTime object. In my entity class I defined… Read more »