# How to subtract two time variables to get seconds

**URL:** <https://forums.losant.com/t/how-to-subtract-two-time-variables-to-get-seconds/3114>\
**Category:** Help\
**Tags:** workflow\
**Created:** [July 13, 2020, 6:50pm UTC](https://forums.losant.com/t/how-to-subtract-two-time-variables-to-get-seconds/3114 "2020-07-13T18:50:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryan\_Chase](https://avatars.discourse-cdn.com/v4/letter/b/5f8ce5/32.png) [@Bryan\_Chase](https://forums.losant.com/u/Bryan_Chase)\
**Post date:** [July 13, 2020, 6:50pm UTC](https://forums.losant.com/t/how-to-subtract-two-time-variables-to-get-seconds/3114/1 "2020-07-13T18:50:35Z")

</div>

Can I use a DATE/TIME block to subtract two times, the results being the number of seconds between the times? How?

I can do this with a FUNCTION node:

```
var lstDate = new Date(payload.working.LastStartTime)
var nowFDate = new Date(payload.time);
payload.currentCycleTime = (nowFDate - lstDate) / 1000; // Convert to seconds

```

Where this is the payload:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/3/342fafdf159c3fccd5f0c850fc9adafd46ac9101.png)

I’ve tried it with a DATE/TIME block but I only see the number of seconds in the time of day sent through.

---

<div class="post-metadata">

**Author:** ![Aidan\_Zebertavage](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/aidan_zebertavage/32/2719_2.png) [@Aidan\_Zebertavage](https://forums.losant.com/u/Aidan_Zebertavage)\
**Post date:** [July 13, 2020, 7:31pm UTC](https://forums.losant.com/t/how-to-subtract-two-time-variables-to-get-seconds/3114/3 "2020-07-13T19:31:45Z")

</div>

Hey @Bryan_Chase,

Yes you can find the difference between two time stamps using the Date/Time node. You want to use the logical function `Diff` that is included in this nodes configuration options in the Operation drop down.

This function returns the difference in milliseconds between the source date and the date provided.

> **[Date/Time Node](https://docs.losant.com/workflows/logic/date-time/#diff)**
>
> Learn more about the Losant Date/Time Node.

Set your `Path of Date to Compare` to `working.LastStartTime` payload path.

Let us know if this solves your issue.

Thanks,  
@Aidan_Zebertavage

---

<div class="post-metadata">

**Author:** ![Bryan\_Chase](https://avatars.discourse-cdn.com/v4/letter/b/5f8ce5/32.png) [@Bryan\_Chase](https://forums.losant.com/u/Bryan_Chase)\
**Post date:** [July 13, 2020, 8:44pm UTC](https://forums.losant.com/t/how-to-subtract-two-time-variables-to-get-seconds/3114/5 "2020-07-13T20:44:59Z")

</div>

Diff produces units of milliseconds. That works, but how would I get seconds?

---

<div class="post-metadata">

**Author:** ![Aidan\_Zebertavage](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/aidan_zebertavage/32/2719_2.png) [@Aidan\_Zebertavage](https://forums.losant.com/u/Aidan_Zebertavage)\
**Post date:** [July 13, 2020, 8:55pm UTC](https://forums.losant.com/t/how-to-subtract-two-time-variables-to-get-seconds/3114/6 "2020-07-13T20:55:30Z")

</div>

@Bryan_Chase,

I would use the Math node and divide the milliseconds by 1000 to perform the conversion to seconds.

> **[Math Node](https://docs.losant.com/workflows/logic/math/)**
>
> Learn more about the Losant Math Node.

Thanks,  
@Aidan_Zebertavage
