Skip to content

Instantly share code, notes, and snippets.

@ckunte
Created July 14, 2019 03:44
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 ckunte/620cf9822899dce6aa108fa90be00b7b to your computer and use it in GitHub Desktop.
Save ckunte/620cf9822899dce6aa108fa90be00b7b to your computer and use it in GitHub Desktop.
Count days from start to end dates
#!/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