Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zf2 is not taking PHP 5 "DateTime" class

I am facing a very weried problem

I am trying to using new php "DateTime" class for date. I am using latest php 5.3.12.

The code works fine when i use normal php code. (I means other non Zend application), but when i used the same code in a controller., it gives me error

Fatal error: Class 'User\Controller\DateTime' not found in C:\wamp\www\1625\module\User\src\User\Controller\UserController.php on line 65

I didn't get because "DateTime" is php inbuild class

The code is below

$date = new DateTime(date('Y').'-'.date('m').'-01'); 
   echo "<li>".$date_now = $date->format('Y-m-d');
like image 862
jyoti Avatar asked Jan 12 '23 20:01

jyoti


1 Answers

Since you are inside a namespace, you should call the base DateTime class as

$date = new \DateTime(date('Y').'-'.date('m').'-01');

which, for clarity, you could rewrite as

$date = new \DateTime(date('Y-m-01'));
like image 128
Matteo Tassinari Avatar answered Jan 16 '23 02:01

Matteo Tassinari