Skip to content

Instantly share code, notes, and snippets.

@kristapsk
Created March 14, 2016 14:45
Show Gist options
  • Save kristapsk/43693f581dbe40af913e to your computer and use it in GitHub Desktop.
Save kristapsk/43693f581dbe40af913e to your computer and use it in GitHub Desktop.
Bash date loop
#! /bin/bash
date_start="2015-01-01"
date_end="2015-12-31"
date_start_unixtime="`date --date="$date_start" +"%s"`"
date_end_unixtime="`date --date="$date_end" +"%s"`"
date_current=$date_start
date_current_unixtime=$date_start_unixtime
echo $date_current_unixtime - $date_end_unixtime
while [ "$date_current_unixtime" -le "$date_end_unixtime" ]; do
date +"%d.%m.%Y" -d "$date_current"
date_current="`date +"%Y-%m-%d" -d "$date_current + 1 DAY"`"
date_current_unixtime="`date --date="$date_current" +"%s"`"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment