Time difference between two timestamps

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:

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

1 Like

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 :laughing:

1 Like

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

DATEDIFF ( datepart , startdate , enddate )

you can check it out here:

and if you want to use expression language just

1 Like