What are the potential pitfalls of using the floor() function when calculating date differences in PHP?

Using the floor() function when calculating date differences in PHP can potentially lead to inaccurate results, especially when dealing with time intervals that cross over into different days. To solve this issue, it is recommended to use the ceil() function instead, as it will round up the result to the nearest whole number.

$date1 = new DateTime('2022-01-01 12:00:00');
$date2 = new DateTime('2022-01-02 12:30:00');

$interval = $date1->diff($date2);
$hours = ceil($interval->h + ($interval->i / 60));

echo "The difference in hours is: " . $hours;