Bluemagica
Bluemagica

Reputation: 5158

php date_diff issue. getting blank result

I am running php 5.3.5 on my local wamp setup. I am running a simple code.

echo "<br/>DEBUGGING";
echo "<br/>===========";
echo "<br/>Date: ".$date;
echo "<br/>Lead Days: ".$lead_days;
echo "<br/>Date diff: ".var_dump(date_diff((int)$date, (int)$lead_days))." difference";

But the output is:

DEBUGGING
===========
Date: 2012-08-31
Lead Days: 2012-09-05

boolean false


Date diff: difference

date_diff seems to return false. I have tried it without var_dump and without int casting, but it always comes blank, however it works if I upload to my webserver. Any ideas what is wrong here?

Upvotes: 1

Views: 1240

Answers (1)

xdazz
xdazz

Reputation: 160833

You can't case date string to int.

date_diff need two DateTime objects as parameter, and return a DateInterval object.

$interval = date_diff(new DateTime($date), new DateTime($lead_days));
echo "<br/>Date diff: " . $interval->d . " days difference";

Upvotes: 4

Related Questions