Skip to content

Instantly share code, notes, and snippets.

@dmaynor
Created June 11, 2015 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmaynor/0bb250c6007b288b63d5 to your computer and use it in GitHub Desktop.
Save dmaynor/0bb250c6007b288b63d5 to your computer and use it in GitHub Desktop.
Echo date range in bash
#!/usr/bin/env bash
# Snippet that finds the current date, subtracts a week, and
# echoes the date range from a week ago to current.
DATE=date
FORMAT="%Y-%m-%d"
now=`$DATE +$FORMAT`
start_time=`$DATE +$FORMAT -d "$now - 1 week"`
while [[ "$start_time" < "$now" ]] ; do
start_time=`$DATE +$FORMAT -d "$start_time + 1 day"`
echo "$start_time"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment