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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Linux/sh...', 1759338230, '216.73.216.88', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Linux/shell/commands/date/arithmetic(48): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78