Hi i am new to perl.

i just got an error when i exceuted the perl script which is as folows:

Day '' out of range 1...31 in C:\..... in line 87

and the code around line 87 is:

sub get_unix_timestamp {
my ($date,$time) = @_;

my $mday = substr($date,0,2);
my $mon = substr($date,3,2);
my $year = substr($date,6,4);

my $hours = substr($time,0,2);
my $min = substr($time,3,2);
my $sec = substr($time,6,2);

my $time_stamp = timegm ($sec, $min, $hours, $mday, $mon, $year);
return $time_stamp;
}

What data do you pass into the function? Which module are you using that imports the timegm() function?

What data do you pass into the function? Which module are you using that imports the timegm() function?

The nodules which i am using are:
use warnings;
use Text::ParseWords;
use Time::Local;
use strict;

and passing 06.10.2008,06:28:32 this to the subroutine.

Works for me. But you do have to subtract 1 (one) from the month because Time::Local and the timexxxx() functions uses 0-11 for the months of the year the same as localtime() does.

use warnings;
#use Text::ParseWords;
use Time::Local;
use strict;

my $r = get_unix_timestamp('06.10.2008','06:28:32');
print scalar localtime($r);

sub get_unix_timestamp {
my ($date,$time) = @_;

my $mday = substr($date,0,2);
my $mon = substr($date,3,2);
my $year = substr($date,6,4);

my $hours = substr($time,0,2);
my $min = substr($time,3,2);
my $sec = substr($time,6,2);

my $time_stamp = timegm ($sec, $min, $hours, $mday, $mon-1, $year);
return $time_stamp;
}

I suggest you print out the values in the sub routine as you run the code to see whats going on.

I did this for each and every step the script runs. everything is fine no problem at all except for the day out of range error.

Well, I'm not sure what to tell you. The day range must fall between 1 and 31, if it doesn't you get the error that you are getting. Your script with your sample data works fine for me.

This article has been dead for over six months. Start a new discussion instead.