Perl Oneliner for date calculation
Perl is great for writing oneliner scripts to do simple task. I’m often confounded that there are no inherent unix utilities for doing date arithmetic / calculations, since so many unix utilities require the date as an option. Thanks to the Perl Date::Calc module, that isn’t an issue.
Here’s a one liner to find out what the date was 28 days (4 weeks) ago:
perl -e 'use Date::Calc qw(Today Add_Delta_Days); my ($y, $m, $d) = Add_Delta_Days(Today(), -28); print "$y/$m/$d\n";'
Note the value of -28 to tell it to subtract 28 days from the current date. Because it is using Date::Calc, it will correctly handle holidays, different months, leap years, etc (as opposed simply subtracting one from the month which will net you something between 28-31 days).
Note the sexy ISO-8601 return value.