Mittal, Manish wrote:

> The timestap format is YYYY-DD-MM_HH:MM:SS 

Next time you'll need to make your own attempt :

use strict;
use warnings;
use Time::Local;

my $date1 = '2005-06-05_00:00:00';
my $date2 = '2005-06-06_01:02:03';

my $e1 = date2epoch ($date1);
my $e2 = date2epoch ($date2);

my $diff = $e2 - $e1;

# you can format the difference any way you like or just use the value
printf "diff: %u days, %u seconds\n", $diff / 86400, $diff % 86400;
exit;

sub date2epoch {
        my $date = shift;

my @d = ();
push @d, substr $date, 0, 4;    # using substr is probably fdastest method
push @d, substr $date, 5, 2;
push @d, substr $date, 8, 2;
push @d, substr $date, 11, 2;
push @d, substr $date, 14, 2;
push @d, substr $date, 17, 2;
return timelocal $d[5], $d[4], $d[3], $d[2], $d[1] - 1, $d[0] - 1900;

}

__END__
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to