[wplug] cross scripting question

Eric Cooper ecc at cmu.edu
Tue Aug 2 23:09:08 EDT 2005


On Tue, Aug 02, 2005 at 09:44:13PM -0400, Tom Rhodes wrote:
> Basically, what I need is a way to output the date
> subtract one day.  Is there an easy way to do this on Linux?
> 
> I need to print the date in the following format:
> 
> 2005-08-02
> 
> But I want to subtract one day from that (so that the filename
> is one day before the check).

I would use Perl, and the Date::Calc module.  (It's tricky to handle
cases like the day before 2004-03-01, and the day before 2005-01-31,
etc.)

#!/usr/bin/perl -w
use strict;
use Date::Calc qw(Add_Delta_Days);

@ARGV == 1 && $ARGV[0] =~ /^(\d{4})-(\d{2})-(\d{2})$/
    or die "Usage: $0 YYYY-MM-DD\n";

my ($y, $m, $d) = Add_Delta_Days($1, $2, $3, -1);
printf "%04d-%02d-%02d\n", $y, $m, $d;


More information about the wplug mailing list