Pankaj
Pankaj

Reputation: 10095

DateTime::createFromFormat() expects parameter 2 to be string, object given

I am trying to get output as Current date and Time as 0:0:0 Below is my code.

$StartDate = new \DateTime('now');
$StartDate = $StartDate->setTime(0, 0, 0);
echo \DateTime::createFromFormat('Y-m-d', $StartDate);

but I am getting error below.

DateTime::createFromFormat() expects parameter 2 to be string, object given

Upvotes: 3

Views: 10023

Answers (2)

rome 웃
rome 웃

Reputation: 1901

Get start day && end day:

$date = date('Y-m-d');
$startDate = new \DateTime($date);
$endDate = new \DateTime($date);
$endDate->modify("+1 day -1 second");

echo $startDate->format('Y-m-d H:i:s');
return dd($endDate);

Upvotes: 3

Chris
Chris

Reputation: 59511

change your output to:

echo $StartDate->format('Y-m-d H:i:s');

Here's a list of all the formatting characters that can be used to customize your output Link

Upvotes: 0

Related Questions