Reputation: 279
date=$(date +%Y_%m_%d_%H_%M)
echo "CURRENT DATE-->" "$date"
How to round it off to the nearest five minutes? For example, the output should be:
2016_01_20_17_20
Upvotes: 1
Views: 1599
Reputation: 246837
date -d @$(( (($(date +%s) + 150) / 300) * 300)) "+%Y_%m_%d_%H_%M"
The inner date call returns the epoch time in seconds, and then rounds (up or down) to nearest multiple of 300 (5 minutes). The outer date call formats as desired.
Upvotes: 4