Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JFFail
Last active July 31, 2020 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JFFail/dee8f161b4bd3ed7a842 to your computer and use it in GitHub Desktop.
Save JFFail/dee8f161b4bd3ed7a842 to your computer and use it in GitHub Desktop.
Solution to Reddit Daily Programmer 201
#!/usr/pkg/bin/zsh
dateMath() {
todayMonth=$(date "+%m/%d/%y" | awk -F\/ '{print $1}' | sed "s/^0//")
todayDay=$(date "+%m/%d/%y" | awk -F\/ '{print $2}' | sed "s/^0//")
todayYear=$(date "+%m/%d/%y" | awk -F\/ '{print $3}' | sed "s/^0//")
today="$todayMonth/$todayDay/$todayYear"
current=$(date -d $today +%s)
submitted=$(date -d $1 +%s)
diffDays=$((($submitted - $current) / 86400))
echo "You must wait $diffDays days from $today to $1"
}
input="2016 2 9"
year=$(echo $input | awk '{print $1}')
month=$(echo $input | awk '{print $2}')
day=$(echo $input | awk '{print $3}')
inputDate="$month/$day/$year"
dateMath $inputDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment