Get timestap difference


I am working with PostgreSQL and I am saving timestamps as “timestamp without timezone”. I want to run queries to the database, get some timestamps and get the difference between them in milliseconds but I am having problems with python when I try to get the difference. ¿How could I do so?

This is the date format I get → Tue Sep 02 09:41:21 CEST 2014
Thank you!!


Can you be more specific about what you expect and what is happening? Perhaps being able to see the part of the script where you output the result will help, too.

I used the following script to test [code]result1 = system.db.runQuery(“SELECT t_stamp FROM sqlt_data_1_2013_10 limit 1”)
result2 = system.db.runQuery(“SELECT t_stamp FROM sqlt_data_2_2013_12 limit 1”)
time1 = result1[0][0]
time2 = result2[0][0]
diff = time2 - time1

print time1
print time2
print diff[/code] and got this (expected) result: 1381345702898 1386121501669 4775798771

You can do it in one query by using:

SELECT EXTRACT(EPOCH FROM (SELECT timestamp1 FROM table WHERE ...) - (SELECT timestamp2 FROM table WHERE ...)) * 1000

Thank you SeanT it worked perfectly :slight_smile: