Skip to content

Instantly share code, notes, and snippets.

@avh4
Created June 10, 2012 19:34
Show Gist options
  • Save avh4/2907056 to your computer and use it in GitHub Desktop.
Save avh4/2907056 to your computer and use it in GitHub Desktop.
List the weeks between now and a given date
#!/bin/bash
# Lists the weeks between now and $1. You may specify the end date in any
# way that GNU date accepts, such as "Aug 25", "next year" or "2 months".
#
# If your system date is BSD date (like on Mac OS X), you will need to install
# GNU coreutils, ideally with http://mxcl.github.com/homebrew/
# "brew install coreutils"
FORMAT="Week of %b %e, %Y: "
DAY_TO_PRINT="Monday"
DATE_CMD="gdate" # Use gdate if your system date is BSD date (Mac OS X)
# DATE_CMD="date" # Use this if your system date is GNU date (Linux)
END_T="`$DATE_CMD -d "$1" +%s`"
NEXT_WEEK=0
NEXT="$DAY_TO_PRINT +$NEXT_WEEK week"
NEXT_T="`$DATE_CMD -d "$NEXT" +%s`"
while [ "$NEXT_T" -lt "$END_T" ]; do
gdate -d "$NEXT" +"$FORMAT"
NEXT_WEEK="$(($NEXT_WEEK + 1))"
NEXT="$DAY_TO_PRINT +$NEXT_WEEK week"
NEXT_T="`$DATE_CMD -d "$NEXT" +%s`"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment