How do you get the current hour and the nearest hour, e.g.
The time is now 2:25PM
.
The current hour is 2:00PM
The nearest hour to be 2:59PM
(not 3PM
, as 2:59PM
will do).
How do you get the current hour and the nearest hour, e.g.
The time is now 2:25PM
.
The current hour is 2:00PM
The nearest hour to be 2:59PM
(not 3PM
, as 2:59PM
will do).
If I understand correctly:
<?php
$hour = date("g:00A"); // or "G" for 24-hour clock
$nearest_hour = date("g:59A");
?>
You can try something like this:
$hour = date('H');
$min = date('i');
if($min > 30)
{
$closest_hour = $hour +1;
}
elseif($min < 30)
{
$closest_hour = $hour;
}
else
{
//Here is exactly half past $hour so you decide what to do :)
}
HTH!
So you have HH:MM.
Why just keep HH and add 59 next to it ? Isn't that work all the time ?