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

Anybody knows the script to calculate or to display dates between range?

Replies are listed 'Best First'.
Re: Script to display dates between range
by ikegami (Patriarch) on Mar 10, 2010 at 03:27 UTC

    One way, using DateTime:

    use strict; use warnings; use DateTime qw( ); my $sdt = DateTime->new( year => 2010, month => 3, day => 9, ); my $edt = DateTime->new( year => 2010, month => 3, day => 16, ); for (my $dt = $sdt->clone(); $dt<=$edt; $dt->add( days => 1 )) { print($dt->ymd(), "\n"); }
    2010-03-09 2010-03-10 2010-03-11 2010-03-12 2010-03-13 2010-03-14 2010-03-15 2010-03-16
      Thanks a lot for replying.....if I am giving an input in terms of string dates in the form of yyyy-mm-dd then how to handle such a input in above code
        You could use a regex to parse. You could use one of the DateTime::Format modules.
        use strict; use warnings; use DateTime::Format::ISO8601 qw( ); my $sdt = DateTime::Format::ISO8601->parse_datetime('2010-03-09'); my $edt = DateTime::Format::ISO8601->parse_datetime('2010-03-16'); for (my $dt = $sdt->clone(); $dt<=$edt; $dt->add( days => 1 )) { print($dt->ymd(), "\n"); }

        Or ...

Re: Script to display dates between range
by ungalnanban (Pilgrim) on Mar 10, 2010 at 13:12 UTC
    You can you this following code for print the date between the range
    use strict; use warnings; my $command; foreach(1..5) { $command = "date -d \"+ $_ day\""; system ("$command"); }
    Output:
    Thu Mar 11 18:39:56 IST 2010
    Fri Mar 12 18:39:56 IST 2010
    Sat Mar 13 18:39:56 IST 2010
    Sun Mar 14 18:39:56 IST 2010
    Mon Mar 15 18:39:56 IST 2010

    --sugumar--
Re: Script to display dates between range
by ambrus (Abbot) on Mar 11, 2010 at 07:50 UTC