# Calculating the time between a DATETIME and now

**URL:** <https://forum.inductiveautomation.com/t/calculating-the-time-between-a-datetime-and-now/21151>\
**Category:** Ignition\
**Created:** [November 30, 2018, 12:20am UTC](https://forum.inductiveautomation.com/t/calculating-the-time-between-a-datetime-and-now/21151 "2018-11-30T00:20:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bellm](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@bellm](https://forum.inductiveautomation.com/u/bellm)\
**Post date:** [November 30, 2018, 12:20am UTC](https://forum.inductiveautomation.com/t/calculating-the-time-between-a-datetime-and-now/21151/1 "2018-11-30T00:20:48Z")

</div>

I have a Historical Transaction Group where I would like to calculate the time difference between two specific event triggers. Here is what my transaction group looks like:

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/0/02590e8bc88a1051bd25357485665e3efd76e2f0.png)

Inside of the DryTime tag I am calculating the amount of time from NOW() and when the part was “set”. Here is that code:

```auto
SELECT CONCAT(TIMESTAMPDIFF(Hour,TimeStamp,NOW()), ":", 
	Lpad(MOD(TIMESTAMPDIFF(MINUTE,TimeStamp,NOW()),60),2,0), ":",  
	Lpad(MOD(TIMESTAMPDIFF(SECOND,TimeStamp,NOW()),60),2,0)) AS DryTime
FROM event_history
WHERE hangers_id = {[~]hangers_id} 
	AND Room = {[~]Events/HistoryTransaction/Room} 
	AND EventDescription LIKE "%set%"

```

This part is working as expected. Though I suspect I might have an issue if the EventDescription ever includes the “set” characters.

The road block I am facing is how to only run this calculation when the trigger is a “pick” or “removed” trigger. As you can see from the following screenshot when a “weight” event is triggered it is also saving the drying time. I would like it to only save the drying time when there is a “set” event.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/34341e4ffadfb83da6f44649858741108325fcc4.png)

Any insight or suggestions would be greatly appericated. SQL programming is not a natural language to me.
