# Time Difference Between 5AM to current Time

**URL:** <https://forum.inductiveautomation.com/t/time-difference-between-5am-to-current-time/93413>\
**Category:** Ignition\
**Created:** [July 18, 2024, 4:36pm UTC](https://forum.inductiveautomation.com/t/time-difference-between-5am-to-current-time/93413 "2024-07-18T16:36:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephanie\_Aguiar](https://avatars.discourse-cdn.com/v4/letter/s/f17d59/32.png) [@Stephanie\_Aguiar](https://forum.inductiveautomation.com/u/Stephanie_Aguiar)\
**Post date:** [July 18, 2024, 4:36pm UTC](https://forum.inductiveautomation.com/t/time-difference-between-5am-to-current-time/93413/1 "2024-07-18T16:36:01Z")

</div>

I am trying to figure out how to make this code work. I see many examples that show how to get the difference between dates but not any for time difference. I would appreciate any help!

 ![Screenshot 2024-07-18 092421](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/1/d1c988f1e54c3d52c396eb927a72bf87164106dd.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 18, 2024, 4:42pm UTC](https://forum.inductiveautomation.com/t/time-difference-between-5am-to-current-time/93413/2 "2024-07-18T16:42:39Z")

</div>

`system.date.getMinutes()` doesn't accept a string as input.  
All of the `system.date` functions either accept or return Java's **Date** class, which represents a date + time as milliseconds since "epoch" (Jan 1, 1970, at midnight UTC).

If you want to get the delta between "right now" and "today at 5 AM", you need to get a datetime that represents "today at 5 AM".  
The way to do that is [`system.date.setTime`](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-date/system-date-setTime), as in:

```python
first = system.date.setTime(system.date.now(), 5, 0, 0)
second = system.date.now()

print system.date.minutesBetween(first, second)

```

---

<div class="post-metadata">

**Author:** ![matt.eaton](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matt.eaton/32/72046_2.png) [@matt.eaton](https://forum.inductiveautomation.com/u/matt.eaton)\
**Post date:** [July 18, 2024, 4:54pm UTC](https://forum.inductiveautomation.com/t/time-difference-between-5am-to-current-time/93413/3 "2024-07-18T16:54:33Z")

</div>

if I can put in my plug to use java.util.Calendar I find it really elegantly handles datetime differences and setting things like 5 am today. But you will end up working in milliseconds instead of cleanly in minutes.
