in reply to Time local

It sounds like the date field you are getting sometimes does not match the pattern you are expecting.

For example, if the date was 2/8/2006 1:14:42 PM, then $amonth would be undef and --$amonth would render -1; hence the error message.

Also, your supplied code snippet is wrong, you are naming the day number as $ayear and the year as $aday.

You need to verify that the date is in the format you are expecting, and perhaps allow for some alternate formats.

Maybe something like (untested):

my $app_time; if( my( $aday, $amonth, $ayear, $ahour, $amin, $asec ) = $appdate =~ m[ (\d{1,2}) [-/] (\d{1,2}) [-/] (\d{4}) \s+ (\d{1,2}) : (\d{1,2}) : (\d{1,2}) ]x ) { $app_time = timelocal( $asec, $amin, $ahour, $aday, --$amonth, $ay +ear ); } else { die "Invalid date (format) '$app_date'"; }

Or you could look into using one of the many date modules from cpan.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.