- date: documentation ( source)
- strtotime: documentation ( source)
<?php
$end_date = new DateTime(date("Y-m-d H:i:s", strtotime("14:00")));
$begin_date = new DateTime(date("Y-m-d H:i:s", strtotime("09:15")));
echo "begin_date is " . $begin_date->format('Y-m-d H:i:s') . " and end_date is " . $end_date->format('Y-m-d H:i:s') . "<br>";
$diff = ($end_date)->diff($begin_date);
$diff_in_hours = $diff->h + $diff->i / 60;
echo "The difference is " . $diff->h . " hours and " . $diff->i . " minutes, which is " . $diff_in_hours . " hours<br>";