Last active
October 26, 2019 11:45
-
-
Save mtavkhelidze/19a8fc7c7f94ebecffc2c8540b618ad9 to your computer and use it in GitHub Desktop.
Bash script to display number of days till a given date.
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 | |
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