I would like to write a bash script that prints out the date in the following format:
20120205_16
(year)(month)(day)_(24 hour)
so the command to do this for the current date is:
date +'20%y%m%d_%H'
What i would like to do is print every date like this (using a for loop or something) from a specified date to another. For example:
20120205_16 -> 20120305_18 would be:
20120205_16
20120205_17
20120205_18
...
20120305_17
20120305_18
Obviously the two hard bits here are specifying the date and incrementing by hour.
Is it possible to do this easily with date or another method?
First, you get
time_tvalues using the%sformat:These are expressed in seconds. You can use a for loop on their values, increasing them by 1 hour (3600 seconds):
Note the
@which is used to express times obtained through%+sin the--dateargument.