Created
July 14, 2019 03:44
-
-
Save ckunte/620cf9822899dce6aa108fa90be00b7b to your computer and use it in GitHub Desktop.
Count days from start to end dates
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 | |
# nd.sh -- count days from start to end dates input inline | |
# 2019 ckunte | |
if [ -z "$*" ]; then | |
echo 'Include "start" "end" dates inline, e.g.,' | |
echo '$ bash nd.sh "1 Apr 2018" "31 Dec 2018"' | |
exit 0 | |
fi | |
start_date=$1 | |
end_date=$2 | |
sdate=$(date --date="$start_date" '+%s') | |
edate=$(date --date="$end_date" '+%s') | |
days=$(( (edate - sdate) / 86400 )) | |
echo "$days days between $start_date and $end_date" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment