find the closest next hour
$nextHour = (intval($date->format('H'))+1) % 24;
echo $nextHour; // 5
Supply any eligible date() to:
function roundToNextHour($dateString) {
$date = new DateTime($dateString);
$minutes = $date->format('i');
if ($minutes > 0) {
$date->modify("+1 hour");
$date->modify('-'.$minutes.' minutes');
}
return $date;
}
Here we go:
<?php
echo date("H:00",strtotime($date. " + 1hour "));
?>
Can you just take pieces (hours, minutes, seconds) and get the next hour?
$dateString = 'Tue, 13 Mar 2012 04:48:34 -0400';
$date = new DateTime( $dateString );
echo $date->format( 'H:i:s' );
echo "\n";
$nexthour = ($date->format('H') + ($date->format('i') > 0 || $date->format('s') > 0 ? 1 : 0)) % 24;
echo "$nexthour:00:00";