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

Let say I define the date as 05.23.2003. How to get tomorrow's date using Date:Calc module... I have this code
use Date::Calc qw(Add_Delta_Days); my (undef, undef, undef, $day, $month,$year) = localtime(); $year+=1900; $month+=1; ($year,$month,$day) = Add_Delta_Days($year,$month,$day, -1); $yesterday = $month.".".$day.".".$year;
this code is to get yesterday's date using localtime() function.. but i want to get tomorrow's date if today's date was defined as 05.23.2003...

Replies are listed 'Best First'.
Re: Tomorrow's date with Date::Calc
by rob_au (Abbot) on Mar 07, 2003 at 09:37 UTC
    Alternatively, without the Date::Calc module, simply add 86400, the number of seconds in a day, to the seconds since epoch returned by time - For example:

    use POSIX; my $date = localtime( time + 86400 ); print POSIX::strftime( '%Y%m%d', $date ), "\n"

     

    perl -le 'print+unpack("N",pack("B32","00000000000000000000001000111011"))'

Re: Tomorrow's date with Date::Calc
by tall_man (Parson) on Mar 07, 2003 at 04:31 UTC
    The solution seems obvious. What am I missing here?
    use strict; use Date::Calc qw(Add_Delta_Days); sub two_digits { return sprintf("%02d",shift); } my $date = "05.23.2003"; my ($month,$day,$year) = split /\./,$date; ($year,$month,$day) = Add_Delta_Days($year,$month,$day, 1); my $tomorrow = join(".", two_digits($month),two_digits($day),$year);
Re: Tomorrow's date with Date::Calc
by ferum (Initiate) on Mar 07, 2003 at 04:36 UTC
    aaa... i think i got the already idea... i'll answer it my self... :)
    use Date::Calc qw(Add_Delta_Days); $arch_date = "20030523"; $year = substr($arch_date,0,4); $month = substr($arch_date,4,2); $day = substr($arch_date,6,2); ($year,$month,$day) = Add_Delta_Days($year,$month,$day, 1); $tomorrow = $month.".".$day.".".$year;