We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

generic PHP DateTime use results in an attempt to find a Phalcon class called DateTime

I need to persist timestamps in my MySQL database that are accurate down to milliseconds. In order to get a string representation of the current system time that is accurate to that level, I need to use the PHP class DateTime. But when I try and create an object:

$ts = new DateTime();
$str = ts->format('Y-m-d H:i:s:u');

The logs complain about 'MyProject\Models\DateTime' not being found (I am using namespaces in this project and the object in question is a Model). Thoughts?


try setting base namespace on datetime like:

$ts = new \DateTime();
$str = ts->format('Y-m-d H:i:s:u');


Yup, that worked, thanks!

You are welcome. If my answer helped you maybe you could mark it as correct answer