Skip to content

Instantly share code, notes, and snippets.

@mtavkhelidze
Last active October 26, 2019 11:45
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 mtavkhelidze/19a8fc7c7f94ebecffc2c8540b618ad9 to your computer and use it in GitHub Desktop.
Save mtavkhelidze/19a8fc7c7f94ebecffc2c8540b618ad9 to your computer and use it in GitHub Desktop.
Bash script to display number of days till a given date.
#!/usr/bin/env bash
till_date=$(echo $1 | tr -d "-")
echo ${till_date} | egrep -q "([0-9]){8,}"
(($? != 0)) && {
echo "Invalid date." 1>&2
echo "Usage: days-till YYYY-MM-DD" 1>&2
echo "Dashes are optional." 1>&2
exit 1
}
till_timestamp=$(date -jf %Y%m%d ${till_date} +%s)
now_timestamp=$(date +%s)
days=$(expr $(expr ${till_timestamp} - ${now_timestamp}) / 86400)
echo ${days} till $(date -r ${till_timestamp} +"%a, %b %e, %Y")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment