# Rounding by 5 minute interval [closed]

How do I round it to the next 5th interval?

``````# date
Sat Oct 13 22:09:25 IST 2012
# date '+%H-%M'
22-09

the output should be
22-10
``````

When the minute is 58 it should round to 00 and not 60 though.

-

## closed as off topic by EEAA♦, Shane Madden♦, Ward, Michael Hampton♦, MagellanOct 14 '12 at 21:42

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

You can tweak this:

``````date '+%H-%M' | awk -F- '{ while( \$2 % 5 != 0 ){ \$2++ }; print \$1, \$2 % 60 }'
``````

Example:

``````\$ date '+%H-%M' | awk -F- '{ while( \$2 % 5 != 0 ){ \$2++ }; print \$1, \$2 % 60 }'
18 55
``````

How it works:

• Split the time over a hyphen
• Increment the minute until it divides 5
• Output the result with the minute modulo 60, so 60 -> 0.
-
Great solution! Just remember to handle rollovers. – Philip Oct 13 '12 at 18:53
The question isn't too clear for me, I thought the user wanted 11:56 -> 11:00 though that's probably not very practical. It'll leave adding one to `\$1` (`% 24`) as an exercise to the reader :-) – Jay Oct 13 '12 at 21:56
Close. But I am not able to round 45-49 to 50 and 05-59 should become 06-00 and not 05 0 – shantanuo Oct 14 '12 at 0:18
Yes, that's because I didn't give you a full solution, only a very large pointer as to how I'd do it. – Jay Oct 14 '12 at 9:52