Juergen Posted September 22, 2016 Share Posted September 22, 2016 Hello @ all, I have created a module which works with dates. I have the following 2 lines of code in my module: 268: $enddate = '2006-12-12'; 269: $end = new DateTime($enddate); If I check the module with Tracy it gives me always the following error: I dont know why the new DateTime class will not be found because it is a standard PHP class. I have added the PW namespace at the top of the module, but it doesnt make any difference whether I add it or not. I am not a PHP pro, so can somebody give me a hint why this leads to an error message? I need this to create time intervals afterwards. Best regards Link to comment Share on other sites More sharing options...
kongondo Posted September 22, 2016 Share Posted September 22, 2016 PW 3? Namespace maybe? \Datetime..maybe..?.....just guessing...Haven't used NS b4 1 Link to comment Share on other sites More sharing options...
adrian Posted September 22, 2016 Share Posted September 22, 2016 Try: new \DateTime($enddate); 3 Link to comment Share on other sites More sharing options...
Juergen Posted September 22, 2016 Author Share Posted September 22, 2016 Thanks at all, I have solved it like this: <?php namespace ProcessWire; use \DateTime; and then $end = new \DateTime($enddate); Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 22, 2016 Share Posted September 22, 2016 The use statement does nothing in you snippet. If you want to use "use", then like this: <?php namespace ProcessWire; use DateTime; $date = new DateTime(); 4 Link to comment Share on other sites More sharing options...
dragan Posted April 10, 2019 Share Posted April 10, 2019 Just stumbled over this yesterday, when I wanted to do a simple date-difference calculation... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now