Skip to content

Instantly share code, notes, and snippets.

@siwells
Last active December 26, 2015 08:19
Show Gist options
  • Select an option

  • Save siwells/7121994 to your computer and use it in GitHub Desktop.

Select an option

Save siwells/7121994 to your computer and use it in GitHub Desktop.
Shell script for Bash on OS X to generate a range of dates given a start date and an end date in the YYYY-MM-DD format.
#!/bin/bash
currentDateTs=$(date -j -f "%Y-%m-%d" $1 "+%s")
endDateTs=$(date -j -f "%Y-%m-%d" $2 "+%s")
offset=86400
while [ "$currentDateTs" -le "$endDateTs" ]
do
date=$(date -j -f "%s" $currentDateTs "+%Y-%m-%d")
echo $date
currentDateTs=$(($currentDateTs+$offset))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment