SPUG: epoch date

tcaine at cac.washington.edu tcaine at cac.washington.edu
Thu Apr 13 11:09:09 PDT 2006


The $mon variable you are passing to timelocal should be in the range 0 .. 
11 instead of 1 .. 12.  Since you initialize the variable to 1 it assumes 
your are talking about February.  February of 2005 only had 28 days.

On Thu, 13 Apr 2006, luis medrano wrote:

> Hey list,
>
> I'm trying to convert dates to epoch dates but my script is giving me
> this error: "Day '29' out of range 1..28 at date.pl line 13". Any of
> you may know what it can be wrong?,
>
> Thanks,
> Luis
>
> P.S. This is the script:
>
>
> #!/usr/bin/perl
> use strict;
> use Time::Local;
> my @months=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
> my $sec=00;
> my $min=00;
> my $hours=14;
> my $mon=1;
> my $year=2005;
> foreach my $month (@months){
>        for (my $day=1; $day<=29;$day++){
>                #next if (($month == $months[1]) && ($day>28));
>                my $epoch=timelocal($sec, $min, $hours, $day, $mon, $year);
>                print" $epoch, $day, $mon, $year \n";
>        }
> $mon++;
> }
>
>
> but I
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>     POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>    MEETINGS: 3rd Tuesdays
>    WEB PAGE: http://seattleperl.org/
>


More information about the spug-list mailing list