Search code examples
phptimeroundinghour

PHP round time and hours


I need to round some times. I would like to know how I can round a time to the next hour and use that as an int in PHP.

Ex:

24:00:02 -> 25  
33:15:05 -> 34  
48:40:30 -> 49

Any ideas?

Regards Claudio


Solution

  • If you handle the time string like a number, PHP treats it like one and removes everyting but the first digits.

    print '48:40:30' + 1; # 49
    print '30:00:00' + 1; # 31