# Time difference between two timestamps

**URL:** <https://forum.inductiveautomation.com/t/time-difference-between-two-timestamps/11511>\
**Category:** Ignition\
**Created:** [April 15, 2016, 11:50am UTC](https://forum.inductiveautomation.com/t/time-difference-between-two-timestamps/11511 "2016-04-15T11:50:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 15, 2016, 11:50am UTC](https://forum.inductiveautomation.com/t/time-difference-between-two-timestamps/11511/1 "2016-04-15T11:50:16Z")

</div>

I was wondering if there is a good way to find the difference between two time stamps. Has anyone ever used system.date.secondsBetween() before? I haven’t and when I tried looking for it online couldn’t really find anything. so basically I want to give it two parameters (both time stamp) and like to get the difference in seconds? Thanks ![:thumb_right:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/2026e28c0c425034352c1b75807edf956adc75f4.gif ":thumb\_right:")

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 15, 2016, 12:33pm UTC](https://forum.inductiveautomation.com/t/time-difference-between-two-timestamps/11511/2 "2016-04-15T12:33:23Z")

</div>

The Java Date objects that Ignition uses as timestamps all over have a ‘time’ property that is milliseconds since the unix epoch. So:`seconds = (javadate1.time - javadate2.time)/1000`

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 15, 2016, 1:48pm UTC](https://forum.inductiveautomation.com/t/time-difference-between-two-timestamps/11511/3 "2016-04-15T13:48:34Z")

</div>

I will look into that. I was thinking of all the possible way to get it done and right now I got it working but using an expression tag and basically for each time stamps, taking out day, hour,min, sec and convert all to sec and add them up and do that same for the other and then subtract them from each other. seems to work fine haha.  
I tend to always do something the annoying and difficult way and then down the line learn the right way to do it 😆

---

<div class="post-metadata">

**Author:** ![Mr.K001](https://avatars.discourse-cdn.com/v4/letter/m/ea5d25/32.png) [@Mr.K001](https://forum.inductiveautomation.com/u/Mr.K001)\
**Post date:** [April 18, 2016, 6:47pm UTC](https://forum.inductiveautomation.com/t/time-difference-between-two-timestamps/11511/4 "2016-04-18T18:47:51Z")

</div>

Quick update guys, If you using MS SQL you can use the following in your query:

```auto
DATEDIFF ( datepart , startdate , enddate )
```

you can check it out here:  
[https://msdn.microsoft.com/en-us/library/ms189794.aspx](https://msdn.microsoft.com/en-us/library/ms189794.aspx)

and if you want to use expression language just

```auto
dateDiff(start,end,field)
```
