Reputation: 109
How can i use the format methode in the Class DateTime in PHP and take some format like :
'Y-m-d H:i' or just the date 'Y-m-d'.
this my code and i putted a picture what i take when i do the dump :
$thisday = new \DateTime(); // I want to take the system date is it ok this instruction ?
$thisday->format('Y-m-d');
dump($thisday);
die();
How can i take just the 2016-04-21 ?
Or take the date, hour and minutes ?
Upvotes: 0
Views: 223
Reputation: 775
format()
does not transform the original DateTime
object into your formatted result, it simply returns your formatted result, which you are not assigning to anything. You need to assign
$thisday->format('Y-m-d');
to a new variable, and use that.
Upvotes: 4
Reputation: 17004
You need to assign the result a variable. DateTime::format
is returning the value, not changing the object itself
$str = $thisday->format('Y-m-d');
dump($str);
Upvotes: 1