I’m getting the time via php
$current_hour = date("G");
Now let’s say the $current_hour is equal to 20. How would I round that to 19? Or if $current_hour is equal to 00 how would I round that to 22? I don’t know if I’m explaining this well, but basically I want to round down each number in intervals of 3 so I get the following:
1
4
7
10
13
16
19
22
[back to begining]
Any number in between should get rounded to the lowest of them so 11 would be 10, 15 would be 13 and so on…
The easy way would be to use integer operations. First divide by 3, then cast to an int, then multiply by 3 again, with some shifting to preserve the sequence you want.
Example: