I want to write a script that will display the time per minute between two date and time. The Start and End time gap can be anything, could be 5minutes, 3hours, 30days, etc.


Start time: 2019-12-31 23:57:00
End Time  : 2020-01-01 00:03:00


 2019-12-31 23:57:00
 2019-12-31 23:58:00
 2019-12-31 23:59:00
 2020-01-01 00:00:00
 2020-01-01 00:01:00
 2020-01-01 00:02:00
 2020-01-01 00:03:00

Edit: Im getting the error below when using the -d option.

     date: Not a recognized flag: d
     Usage: date [-u] [+"Field Descriptors"]

With GNU date that can handle expressions like +1 minute, it's pretty easy:

start='2019-12-31 23:57:00'
end='2020-01-01 00:03:00'

while [[ $date < $end || $date == $end ]] ; do
    echo "$date"
    date=$(date -d "+1 minute $date" '+%Y-%m-%d %H:%M:%S')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.