Loading ...
Sorry, an error occurred while loading the content.

strange epoch problem

Expand Messages
  • Muhammad Kamran Azeem
    Hello, I am facing a strange problem. First the scenario. Scenario: I have a date 2004-07-30 07:30:26 and I wanted to know it s equivalent epoch. I used the
    Message 1 of 1 , Oct 3, 2004
    • 0 Attachment
      Hello,

      I am facing a strange problem. First the scenario.

      Scenario:

      I have a date "2004-07-30 07:30:26" and I wanted to know it's
      equivalent epoch.

      I used the following code.

      ##### code START ####

      #$SQLStatement="select lasteventstamp from filesrecord where filename
      = \'$filename\'";
      #$sth = $dbh-> prepare ($SQLStatement) || die "Could not
      prepare:Err:$!\n";
      #my @row=$sth->fetchrow_array;
      #my $lasteventstamp=$row[0];
      my $lasteventstamp="2004-07-30 07:30:26";
      #$sth->finish;
      $lasteventstamp =~
      /(\d{4,4})-(\d{2,2})-(\d{2,2})\s+(\d{2,2}):(\d{2,2}):(\d{2,2})/;
      $year = $1;
      $month = $2;
      $mday =$3;
      $hour =$4;
      $min =$5;
      $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 :
      $lasteventepoch\n";
      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
      Redhat9: 1091151026


      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
      postgresql.

      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.

      Kamran
    Your message has been successfully submitted and would be delivered to recipients shortly.