PugSA has asked for the wisdom of the Perl Monks concerning the following question:

Hi All I need to get a list of dates between two dates.

I've got 2005-08-29 to 2005-09-02

then I need an array eg.
"2005-08-29","2005-08-30","2005-08-31","2005-09-01","2005-09-02"

I looked at something like "Date_GetNext" but I don't think it will work

If anybody knows of a function I can use please let me know

Rgrds
PugSA

Replies are listed 'Best First'.
Re: List of dates between two dates
by fmerges (Chaplain) on Sep 13, 2005 at 08:11 UTC

    Hi,

    You can use Date::Simple

    use Date::Simple (); my $date = Date::Simple->new('1972-01-31'); print $date->next;

    Regards,

    |fire| at irc.freenode.net
Re: List of dates between two dates
by rlb3 (Deacon) on Sep 13, 2005 at 08:12 UTC
      Thank You
Re: List of dates between two dates
by mrkoffee (Scribe) on Sep 13, 2005 at 08:29 UTC

    I've done this using a combination of Date::Simple and Date::Range:

    use Date::Simple qw/date/; use Date::Range; my ( $start, $end ) = ( date('2005-08-29'), date('2005-09-02') ); my $range = Date::Range->new( $start, $end ); my @all_dates = $range->dates;

    HTH,

    Brian

Re: List of dates between two dates
by reasonablekeith (Deacon) on Sep 13, 2005 at 08:29 UTC
    Date::Calc will allow you to roll you own solution for any date manipulation you care to think of. It's written in C too, so is quick. My solution assumes the date format you've defined, so is less flexible than your other answers, but should run quicker.
    #!/perl -w use Date::Calc qw(Add_Delta_Days); use strict; print join(',', get_dates('2005-08-29', '2005-09-02')); #============================================================== sub get_dates { my ($from, $to) = @_; my @return_dates = $from; my $intermediate = $from; while ($intermediate ne $to) { $intermediate = sprintf "%04d-%02d-%02d", Add_Delta_Days(spli +t(/-/, $intermediate), 1) ; push @return_dates, $intermediate; } return @return_dates; }
    ---
    my name's not Keith, and I'm not reasonable.