Embed Notice
HTML Code
Corresponding Notice
- Embed this notice@SuperDicq @iro_miya Calculating dates manually is too hard.
Use this GNU bash script instead;
#!/bin/bash
#argument needed
[ "$#" -eq 1 ] || exit 1
#Unix seconds
birthdate=$(date -d "$1" +'%s')
today=$(date -d today +'%s')
seconds_between=$(($today-$birthdate))
#years+months old, no decimal places, no repeats if 0 months
printf "%s %s %s %s %s old today\n" $(units --output-format "%.2g" -- "$seconds_between seconds" 'years;months') | tr --squeeze-repeats ' '