Kevin Old wrote:

> Hello everyone,
> 
> I'm trying to create an array of months that will be a continuous
> "Moving View of Months".  I will have an page served to users that has a
> table of the past 12 months.  For instance, if I were to pull up the
> page today, it would display Apr 02 - Mar 03.  Next month it will be May
> 02 - Apr 03.
> 

not sure if i am reading your question correctly, does the following do what 
you want:

#!/usr/bin/perl -w
use strict;

use Date::Manip;

my $today = ParseDate('now');
my $stop  = UnixDate($today,'%m/%Y');
my $pass  = ParseDate('-12 months');
my %range;

while(1){
        $pass = DateCalc($pass,"1 month");
        my $should_stop = UnixDate($pass,'%m/%Y');
        $range{$should_stop} = 1;
        last if($should_stop eq $stop);
}

print "$_\n" for(sort { my($pmonth,$pyear) = $b =~ m#(.+)/(.+)#;
                        my($month,$year)   = $a =~ m#(.+)/(.+)#;
                        $year cmp $pyear || $month cmp $pmonth
                        } keys %range);

__END__

prints:

04/2002
05/2002
06/2002
07/2002
08/2002
09/2002
10/2002
11/2002
12/2002
01/2003
02/2003
03/2003

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to