2014-02-11 Since a long time, I think, that Unix is missing a clever date arithmetic tool, such as bc(1). At least calculating the differ- ences of two dates should be easy. To fill this gap, I wrote a rudimentary, but better-than-nothing tool, called `datediff'. It can print the difference in years, months (30 days! :-( ), weeks, days, hours, minutes, and of course seconds. The script is a quick hack. It's main shortcoming is the 30-day month. Nonetheless, the script is already helpful. #!/bin/sh if [ $# -lt 2 ] ; then echo "Usage: ${0##*/} -YmWdHMS date1 [date2]" >&2 exit 1 fi d1=`date +%s -d "$2"` if [ $# -eq 3 ] ; then d2=`date +%s -d "$3"` else d2=`date +%s` fi diff=`expr "$d2" - "$d1"` case "$1" in -Y) echo `expr $diff / 60 / 60 / 24 / 365` years ;; -m) echo `expr $diff / 60 / 60 / 24 / 30` months ;; # FIXME -W) echo `expr $diff / 60 / 60 / 24 / 7` weeks ;; -d) echo `expr $diff / 60 / 60 / 24` days ;; -H) echo `expr $diff / 60 / 60` hours ;; -M) echo `expr $diff / 60` minutes ;; -S|*) echo $diff seconds ;; esac http://marmaro.de/lue/ markus schnalke