Gunga Din Gunga Din - 2 years ago 122
PHP Question

PHP - How to "add hours" to an integer?

I want something that seems simple but can't figure out :

I have an integer which in my program is an hour, in a 24h format (ie '18') and I want to add X (ie '7') hours to it.

How do I add hours to something that is not at date object whatsoever. Something that would work like this :

18 + 7 = 1

Answer Source

Using the modulus operator is what you're after. See this example:

echo ((18 + 7) % 24); // Output: 1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download