user3209287
user3209287

Reputation: 219

DateTime class php cause bug in Laravel 5.1?

I used this code in my controller of a project using Laravel 5.1 :

$start_date = "2015-06-10";
$date = new DateTime($start_date);

But always I run code in server both Chrome and Firefox, my web seem to be "dead" in that line, it show the error : 500 Internal server error, and after many debug, I found that bug.

Anyone can give me solution to fix that, thanks :(

Upvotes: 1

Views: 2078

Answers (1)

ExoticChimp
ExoticChimp

Reputation: 1904

try

$start_date = new \DateTime();
$start_date->createFromFormat('d/m/Y', '10/06/2015');

You need to add the slash to reference the class in the root namespace, or just add the following at the top:

use Datetime;

Upvotes: 2

Related Questions