How to get the hour and the next hour

Hey guys, just a question.

How do you get the current hour and the next hour, for example.

Now is the time . 2:25PM

Current hour 2:00PM

The next hour (not how it will be done ). 2:59PM3PM2:59PM

Greetings.

+3
source share
4 answers

You can use the date function :

$current = date("g:00A");
$next = date("g:59A");

If you want in real time:

$now = date("g:iA");
+5
source

If I understand correctly:

<?php
$hour = date("g:00A"); // or "G" for 24-hour clock
$nearest_hour = date("g:59A");
?>
+2
source

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!

+1
source

So you have HH: MM.

Why just keep HH and add 59 next to it? Doesn't it work all the time?

0
source

All Articles