1
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
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Mohit Rane
  • 279
  • 7
  • 23
  • Possible duplicate of [bash round minutes to 5](https://stackoverflow.com/q/22783007/608639) – jww Aug 30 '18 at 08:53

1 Answers1

4
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.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352