in reply to Date::Calc Module

I like maverick's suggestion better, but here is some code for you to toy with to get the hang of the somewhat hard to get the hang of Date::Calc
use strict; use Date::Calc qw(Add_Delta_YMD Delta_Days); my $date1 = '2001/12/25/'; # Dec 25, 2001 my ($d,$m,$y) = (localtime)[3..5]; my $today = join('/', $y+1900, $m+1, $d); # add x days to date1 my $date2 = join('/', Add_Delta_YMD( split('/',$date1), # date 1 0,0,4 # plus 4 days ) ); # compare it to today's date print "same day\n" if Delta_Days( split('/',$date2), split('/',$today), ) == 0;
I also recommend getting a copy of the Perl Cookbook, chapter 3 is devoted solely to working with dates.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

Replies are listed 'Best First'.
Re: (jeffa) Re: Date::Calc Module
by skirrow (Novice) on Dec 29, 2001 at 22:53 UTC
    Hi, No matter what I change $date1 to, it returns 'same day'!? - Neil
      If you change the day portion, you will not get 'same day'. However, if you change the year or the month without changing the day, you will. The reason is because i chose to compare the dates by the number of days - not the year and/or month.

      Like I said, this is just to get you going.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      F--F--F--F--F--F--F--F--
      (the triplet paradiddle)