# Get timestap difference

**URL:** <https://forum.inductiveautomation.com/t/get-timestap-difference/8982>\
**Category:** Ignition\
**Created:** [September 2, 2014, 9:58am UTC](https://forum.inductiveautomation.com/t/get-timestap-difference/8982 "2014-09-02T09:58:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lauravsp](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@lauravsp](https://forum.inductiveautomation.com/u/lauravsp)\
**Post date:** [September 2, 2014, 9:58am UTC](https://forum.inductiveautomation.com/t/get-timestap-difference/8982/1 "2014-09-02T09:58:37Z")

</div>

Hi

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!!

Laura

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/37d1977bd9a8f5c139de143a8c4f7011814fe2f4.PNG)

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [September 2, 2014, 3:15pm UTC](https://forum.inductiveautomation.com/t/get-timestap-difference/8982/2 "2014-09-02T15:15:11Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![SeanT](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@SeanT](https://forum.inductiveautomation.com/u/SeanT)\
**Post date:** [September 2, 2014, 7:24pm UTC](https://forum.inductiveautomation.com/t/get-timestap-difference/8982/3 "2014-09-02T19:24:05Z")

</div>

You can do it in one query by using:

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

---

<div class="post-metadata">

**Author:** ![lauravsp](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@lauravsp](https://forum.inductiveautomation.com/u/lauravsp)\
**Post date:** [September 4, 2014, 1:35pm UTC](https://forum.inductiveautomation.com/t/get-timestap-difference/8982/4 "2014-09-04T13:35:12Z")

</div>

Thank you SeanT it worked perfectly 🙂
