Symfony 4 - Set DateTime
If your date is the current date, you can just do this:
$category->setCreatedTs(new \DateTime())
Your first error was caused by the strtotime
function that returns a timestamp but the \DateTime constructor was expecting a Y-m-d H:i:s
format.
That's why instead of creating a valid \DateTime, it returned false.
Even if it's unnecessary in this case, you should have done something like this to create a \DateTime
based on a timestamp:
$date = new \DateTime('@'.strtotime('now'));