Computing Days Between Dates with bash

less than 1 minute read

This script will compute the days between dates.

# adapted from https://www.linuxforfreshers.com/2019/01/how-to-count-days-since-specific-date.html
if [ $# -ne 2 ]; then
    echo "USAGE: $(basename $0) start_date end_date";
    exit 1;
else
  start=$1;
  end=$2;
  echo "$((($(date +%s --date "$end") - $(date +%s --date "$start"))/(3600*24))) days between $start and $end";
fi