Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date_diff() expects parameter 1 to be DateTimeInterface, string given

Tags:

php

datediff

They have the same format:

$date_expire = '2014-08-06 00:00:00';
$date1 = date("Y-m-d G:i:s");
$date2 = date_create($date_expire);

$diff = date_diff($date1, $date2); //this line makes error.

But I am getting this error:

date_diff() expects parameter 1 to be DateTimeInterface, string given

like image 228
ShelðÔn Alag Avatar asked Jul 07 '14 10:07

ShelðÔn Alag


1 Answers

Because you are passing string whereas date_diff expects datetime object,

$date_expire = '2014-08-06 00:00:00';    
$date = new DateTime($date_expire);
$now = new DateTime();

echo $date->diff($now)->format("%d days, %h hours and %i minuts");

DEMO.

like image 102
Rikesh Avatar answered Sep 19 '22 23:09

Rikesh