How do you create a DateTime from timestamp in versions less than < 5.3?
In 5.3 it would be:
$date = DateTime::createFromFormat('U', $timeStamp);
The DateTime constructor wants a string, but this didn't work for me
$date = new DateTime("@$timeStamp");
It's not working because your $timeStamp variable is empty. Try echoing the value of $timeStamp right before creating the DateTime and you'll see. If you run this:
You don't get an error. However, if you run:
It produces the exact error you said it gives you. You'll need to do some debugging and find out why $timeStamp is empty.
PHP 5 >= 5.3.0
Edit: Added correct PHP version for
setTimestamp
The following works:
Assuming you want the date and the time and not just the date as in the previous answer:
Seems pretty silly to have to do that though.