Hey guys, just a question.
How do you get the current hour and the next hour, for example.
Now is the time . 2:25PM
2:25PM
Current hour 2:00PM
2:00PM
The next hour (not how it will be done ). 2:59PM3PM2:59PM
2:59PM
3PM
Greetings.
You can use the date function :
$current = date("g:00A"); $next = date("g:59A");
If you want in real time:
$now = date("g:iA");
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 :) }
NTN!
So you have HH: MM.
Why just keep HH and add 59 next to it? Doesn't it work all the time?