Hi Carol, it's me again still messing with my date/time sort deally-bob. The last time you helped me with a (human date/time) to Unix coversion. Well I am just now getting back to work on that and I have found a new problem.
I think I need a zero stripping function to strip the zero's from the human date $hour, $min, $sec
Here is the date/time format I am using:
Aug-17-1999 08:00:49
The PostTime field equals the above date/time string.
my $SortDate = &date_to_unix("$rec{'PostTime'}");
I am passing the above date string to the date-to-unix sub but whenever the hour changes it comes up with the wrong unix time.
Here is my date-to-unix sub:
sub date_to_unix {
my ($date) = $_[0];
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($mon, $day, $year, $hour, $min, $sec) = split(/ /, $_[0]);
my ($mon, $day, $year) = split(/-/, $_[0]);
my ($hour, $min, $sec) = split(/:/, $_[0]);
unless ($mon and $day and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal($sec,$min,$hour,$day,$months{$mon},$year);
};
if ($@) { return undef;} # Could return 0 if you want.
return ($time);
}
Don't I need to add the reverse of this to strip the zero's ?
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");
This I copied from my get date/time sub, I know the above adds zero's if less than 10. I just don't know how to remove them in the date-to-unix sub or if I have to.
Remember my date sort has to include the time, that is why we came up with a combined date/time sub.
I think this is my last big hurtle once I get past this I'm home free. Yeehah
I hope things are going well for you
I think I need a zero stripping function to strip the zero's from the human date $hour, $min, $sec
Here is the date/time format I am using:
Aug-17-1999 08:00:49
The PostTime field equals the above date/time string.
my $SortDate = &date_to_unix("$rec{'PostTime'}");
I am passing the above date string to the date-to-unix sub but whenever the hour changes it comes up with the wrong unix time.
Here is my date-to-unix sub:
sub date_to_unix {
my ($date) = $_[0];
my (%months) = ("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, "Jun" => 5,
"Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, "Nov" => 10,"Dec" => 11);
my ($time);
my ($mon, $day, $year, $hour, $min, $sec) = split(/ /, $_[0]);
my ($mon, $day, $year) = split(/-/, $_[0]);
my ($hour, $min, $sec) = split(/:/, $_[0]);
unless ($mon and $day and $year) { return undef; }
unless (defined($months{$mon})) { return undef; }
use Time::Local;
eval {
$day = int($day); $year = int($year) - 1900;
$time = timelocal($sec,$min,$hour,$day,$months{$mon},$year);
};
if ($@) { return undef;} # Could return 0 if you want.
return ($time);
}
Don't I need to add the reverse of this to strip the zero's ?
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");
This I copied from my get date/time sub, I know the above adds zero's if less than 10. I just don't know how to remove them in the date-to-unix sub or if I have to.
Remember my date sort has to include the time, that is why we came up with a combined date/time sub.
I think this is my last big hurtle once I get past this I'm home free. Yeehah
I hope things are going well for you