strange epoch problem
I am facing a strange problem. First the scenario.
I have a date "2004-07-30 07:30:26" and I wanted to know it's
I used the following code.
##### code START ####
#$SQLStatement="select lasteventstamp from filesrecord where filename
#$sth = $dbh-> prepare ($SQLStatement) || die "Could not
my $lasteventstamp="2004-07-30 07:30:26";
$year = $1;
$month = $2;
$sec = $6;
$month--; ## timelocal function uses months from 0-11
$month =~ s/^0//g; # remove left zeros from all numbers
$mday =~ s/^0//g;
$hour =~ s/^0//g;
$min =~ s/^0//g;
$sec =~ s/^0//g;
$lasteventepoch = timelocal($sec, $min, $hour, $mday, $month, $year);
print "EPOCH of $year,$month,$mday $hour:$min:$sec is :
print "REVERSED:" . localtime ($lasteventepoch) . "\n";
#### code END ####
The problem is when I run this code on my home machine (dual boot
Mandrake 10 and RedHat9) I recieved the following Results:
Mandrake 10: 1091187026
Today when I run this code on my office computer 1 (Mandrake 10) I got
the result as : 1091154626
And when I run the same code on my office computer 2 (rehat 9) I got
the result as : 1091151026
Question Number 1: Where am I being wrong, or is there problem with
any of these distributions?
More: Basically I am getting this timestamp from a table field in
when I run this query on my Mandrake 10 computer:-
select EXTRACT(EPOCH FROM lasteventstamp) as epoch ;
I get the result as : 1091187026
and when I run the same QUERY on Redhat9 computer :-
I get result as : 1091172626
Question Number 2: Which of the above solutions is reliable ? Which
one should I use? Why there is a difference of epochs between linux
distributions or postgres versions. I know this is not a postgres
list. Why I wrote this all here is that basically / primarly I am
getting this date from postgres and comparing the epoch with the dates
picked up from a text file. Once I convert the same date picked from
file using perl into epoch , I get diffrent epoch. And when I use the
built in extract function of postgres on the same date coming from
table, I get a different epoch. I am also posting this question to
postgres mailing list.
Mean while I hope some one can point me in the rigth direction why
this strange behavior I am observing.
Thankyou for your time and effort.