1

I'm trying to round my time to nearest hour, but every time I fail.

Is it possible to round time, but not change the structure? I tried to use ceil and floor, but I failed...

$date = "2015/04/20 06:59"; 
$date = date("Y/m/d H:0",strtotime($date));
print $date; //Need to print 2015/04/20 07:00
Xinel
  • 119
  • 13
  • http://stackoverflow.com/questions/9639642/how-to-round-unix-timestamp-up-and-down-to-nearest-half-hour – JoeCoder Mar 17 '15 at 17:22

1 Answers1

2

Not sure about rounding but you could do something like this:

$hour = date('H');
$minutes = date('i');

if ($minutes >= 30) 
{
    $hour++;
}

Oh, use modulo: How to round unix timestamp up and down to nearest half hour? (cheers @JoeCoder)

Community
  • 1
  • 1
diggersworld
  • 12,770
  • 24
  • 84
  • 119