use strict;
use warnings;

use Time::Local;

my $days1 = epoch_days('30-Jan-09');
my $days2 = epoch_days('14-Feb-2009');

print "Difference: @{[$days1 - $days2]} days\n";

BEGIN {

  my %month_num = do {
    my $n = 1;
    map(($_, $n++), qw/jan feb mar apr may jun jul aug sep oct nov dec/);
  };

  sub epoch_days {

    my @dmy = split /-/, shift;
    $dmy[1] = $month_num{lc $dmy[1]} || 0;

    return timelocal(0, 0, 0, @dmy) / (24 * 60 * 60);
  }
} 




>-----Original Message-----
>From: Owen [mailto:rc...@pcug.org.au] 
>Sent: Friday, January 30, 2009 4:43 PM
>To: S, Rajini (STSD)
>Cc: Perl Beginners
>Subject: RE: Query in Perl Programming
>
>>
>> Get the same error, when the date is set to
>>
>> my $days1 = epoch_days('30-Jan-09');
>> my $days2 = epoch_days('14-Feb-2009');
>>
>> Day '30' out of range 1..28 at ./date2.pl line 35
>>
>> -Rajini
>>
>>
>>
>>
>>
>>
>>>-----Original Message-----
>>>From: Owen [mailto:rc...@pcug.org.au]
>>>Sent: Friday, January 30, 2009 4:09 PM
>>>To: S, Rajini (STSD)
>>>Cc: Perl Beginners
>>>Subject: RE: Query in Perl Programming
>>>
>>>>
>>>> Hi Rob,
>>>>
>>>> When I set the date to 30-Jan-2009 and run the code given below,
>>>>
>>>> Eg :
>>>>
>>>> When dates are set as :
>>>>
>>>> my $days1 = epoch_days('30-Jan-09'); my $days2 = 
>>>> epoch_days('29-Feb-2009');
>>>>
>>>> I get the below error.
>>>>
>>>> hpcll402:/home/ssssraji/perl>./date2.pl
>>>> Day '30' out of range 1..28 at ./date2.pl line 35
>>>>
>>>
>>>
>>>Feb 2009 has 29 fays?
>>
>
>OK, well it looks like your program is thinking Jan is February.
>
>Show us your program
>
>
>Owen
>
>
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to