Created
June 11, 2015 20:12
-
-
Save dmaynor/0bb250c6007b288b63d5 to your computer and use it in GitHub Desktop.
Echo date range in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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