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.

I'm able to create the array, but think there might be a much more
efficient way to do it.

Basically what I do is use UnixDate from Date::Manip to get the date
from 11 months ago (split that into an array for &date_range) then I get
a list of dates from 11 months ago until today.  I've yet to write the
code to parse the array of dates and pluck out the first of each month
and put into an array.

Have a look at my code below.  Any pointers/suggestions are appreciated!

#!/usr/bin/perl -w
#
use strict;
use Date::Calc qw(Delta_DHMS Delta_Days Add_Delta_Days Date_to_Text
Today);
use Date::Manip qw(UnixDate);

my $ea = &UnixDate("-11 months", "%Y,%m,%d");
print "$ea\n";
my @elevenago = split/,/, $ea;

my @today = Today();
my @dates = ();
my @range = &date_range(@elevenago, @today);
# @range is a list of days from @elevenago to @today

sub date_range {

        my(@date) = (@_)[0,1,2];
        my(@list);
        my($i);

        $i = Delta_Days(@_);
        while ($i-- >= 0)
        {
                        push( @list, [ @date ] );
                        @date = Add_Delta_Days(@date, 1) if ($i >= 0);
        }
        return(@list);
}#end date_range

Thanks,
Kevin
-- 
Kevin Old <[EMAIL PROTECTED]>


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

Reply via email to