ltdev
ltdev

Reputation: 4457

PHP date_diff() - find number of days and convert to hours

I wan't to find the date difference between to days and then convert it into hours

$date_diff = date_diff($latest_date, $oldest_date);
echo $date_diff->format(???);

I have tried to set format as ->format('h'); but didn't work. How can I do this?

Upvotes: 1

Views: 229

Answers (1)

Sofiene Djebali
Sofiene Djebali

Reputation: 4508

This should work:

PHP

$datetime1 = date_create('2009-10-11');
$datetime2 = date_create('2009-10-13');
$interval = date_diff($datetime1, $datetime2);

echo 'Days : ' . $interval->days. '  ';
echo 'Hours : ' . $interval->days * 24;

Upvotes: 2

Related Questions