Search notes:

Shell: Date arithmetic

Calculate difference between two dates in days

dt_1=2022-02-18
dt_2=2023-08-28
dt_1_sec=$(  date -d $dt_1 +%s      )
dt_2_sec=$(  date -d $dt_2 +%s      )
dt_d_sec=$(( dt_2_sec - dt_1_sec   ))
dt_d_day=$(( dt_d_sec / 86400      ))
echo "There are $dt_d_day days between $dt_1 and $dt_2"

See also

Adding days (or other intervals) is possible with date -d:
$ date -d 'next friday + 2 days' +%F
Calculating elapsed time in a shell

Index