Inconsistent results when calculating "age" of db records

From: Raheem Sarcar <raheemm1(at)yahoo(dot)com>
To: "psycopg(at)postgresql(dot)org" <psycopg(at)postgresql(dot)org>
Subject: Inconsistent results when calculating "age" of db records
Date: 2012-07-26 06:11:33
Message-ID: 1343283093.68099.YahooMailNeo@web163901.mail.gq1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

Hey All, 

I'm getting inconsistent results when looking up the age of db entries. For items that were added only minutes ago, I get answers like 12 or 13 hours ago. 
In my troubleshooting attempts I ran the following query directly in postgres

select age(pub_date) as days from hackerbiz_story where id=(13);

I get the following output -->
11:24:47.082  (which is correct)

Then I ran the foll query via psycopg2

cur = conn.cursor()
SQL = "select age(pub_date) as days from hackerbiz_story where id=(%s);"
cur.execute(SQL, [storyID])   //storyID is passed as argument

From which I get the following result -->
datetime.timedelta(-1, 45312, 918000).

I then apply the formula "t.seconds/3600" and get the result "12" hrs (which is incorrect).
Can someone help me to troubleshoot this further? The db is locally installed and all the code is also running locally. I'm on the Dhaka timezone. Thanks. 

 
- Raheem M. Sarcar

Responses

Browse psycopg by date

  From Date Subject
Next Message Ghislain LEVEQUE 2012-07-26 07:08:36 Re: Inconsistent results when calculating "age" of db records
Previous Message P. Christeas 2012-07-21 11:34:22 Re: binary protocol, again