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

this has got me stumped, when this code runs i get this error Month '-1' out of range 0..11 at /www/cgi-bin/libraries/Library.pm line 222\n
212 #------------------------------------------------ 213 sub ConvertMysqlTime { 214 my $self = shift; 215 my ( $date , $lpszToUnixStamp ) = @_; 216 217 my @arDateTime = split ( / / , $date ); 218 my @arDate = split ( /-/ , $arDateTime[ 0 ] ); 219 my @arTime = split ( /:/ , $arDateTime[ 1 ] ); 220 $arDate[ 1 ] =~ s/0^//g; 221 222 my $time = timelocal( $arTime[ 2 ] , $arTime[ 1 ] , $ +arTime[ 0 ] , $arDate[ 2 ] , $arDate[ 3 ] , $arDate[ 0 ] ) ; 223 if ( $lpszToUnixStamp eq "false" ) { 224 my ( $sec , $min , $hour , $mday , $month , $y +ear , $wDay , $yDay , $isdst ) = localtime($time); 225 226 $year += 1900; 227 $time = $self->GetWeekDay( $wDay , "Long" ) . +" " . $self->GetMonth( $month , "Long") . " $mday, $year"; 228 } 229 230 return $time; 231 } 232
it ran just fine under perl 5.8 the error only started occuring when i tried to run it on 5.10 Thanks

Replies are listed 'Best First'.
Re: Time::Local issues
by JavaFan (Canon) on Oct 22, 2008 at 20:03 UTC
    It would really help if you also give the arguments to ConvertMysqlTime when you get the error.
Re: Time::Local issues
by Illuminatus (Curate) on Oct 22, 2008 at 20:11 UTC
    What kind of format is the date in? On line 222, your second $arDate arg is $arDate[3]
Re: Time::Local issues
by smiffy (Pilgrim) on Oct 23, 2008 at 04:37 UTC

    Just wondering why you would want to be converting dates coming out of MySQL (if that is what you are doing.) You can get pretty much any format you want from MySQL using date_format() without having to do all that work in Perl. MySQL date and time functions reference