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.

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?



294
Accepted
answer

try setting base namespace on datetime like:

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


17.8k

Yup, that worked, thanks!

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