Convert DateTime to String PHP I before researched a lot of Website on how can i convert PHP DateTime object to String. I always see "String to DateTime" and not "DateTime to String" PHP DateTime can be echoed, but what i want to process my DateTime with PHP string functions. Now my question is how can I make PHP dateTime Object to a string starting from this kind of codes <?php $dts = new DateTime(); //this returns the current date time echo strlen($dts); ?> Solution:
undefined
PHP DateTime class Namespace I'm use the symfony2 framework and I want to use the PHP's DateTime class (PHP version is 5.3). Here the statement: namespace SDCU\GeneralBundle\Entity; class Country { public function __construct(){ $this->insertedAt = new DateTime(); } } But, when execute this constructor, I get an error saying that there's no "SDCU\GeneralBundle\Entity\DateTime" class. I've been searching around for DateTime's namespace but with no success... any idea? Answer: DateTime is in the global namespace, and as "classnames always resolve to the