# How To Tell How Much Time Has Passed?

**URL:** <https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937>\
**Category:** Blueprint\
**Tags:** time, unreal-engine, Blueprint, question\
**Created:** [September 12, 2015, 6:58am UTC](https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937 "2015-09-12T06:58:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![reznorism](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@reznorism](https://forums.unrealengine.com/u/reznorism)\
**Post date:** [September 12, 2015, 6:58am UTC](https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937/1 "2015-09-12T06:58:15Z")

</div>

G’day,

A quick question that probably has a simple answer. Using the datetime functions ([Date Time | Unreal Engine Documentation](https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/DateTime/index.html))

How can I tell how many minutes have passed?

I have a save file for a game, which stores the datetime that it was created. I’d like to check the difference in time between the save files datetime and the current time to see if it’s been more than say, ten minutes. If it has, do this, if it hasn’t, do that.

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [September 12, 2015, 8:17am UTC](https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937/2 "2015-09-12T08:17:39Z")

</div>

There are two ways to do this:

One is to get the actual system time (as you probably did) using the _Now_ node, which returns a _Date Time Structure_, presumably something of the form Year-Month-Day-Hour-Minute-Second. Given such a _Date Time Structure_, you can then query the elements (GetDay, GetHour, GetMinute). So you could implement a function that checks the difference between two such structures by comparing all the date elements. You’ll need to pay attention to overflows: obviously more than ten minutes have passed from 15:23 to 15:42, but the same is true for 15:57 to 16:08. When testing your function, you can manipulate your system clock to test whether you catch all such cases correctly. (Or you might decide that it’s okay if there are some edge cases, such as rolling past midnight, where you just don’t care.)

Alternatively, you could use _Get Real Time Seconds_ (since the session has started) and compare the differences between two second counts. Converting to minutes is easy in this case.

> **[Get Real Time Seconds](https://docs.unrealengine.com/5.2/en-US/BlueprintAPI/Utilities/Time/GetRealTimeSeconds/)**
>
> Get Real Time Seconds

---

<div class="post-metadata">

**Author:** ![reznorism](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@reznorism](https://forums.unrealengine.com/u/reznorism)\
**Post date:** [September 12, 2015, 12:46pm UTC](https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937/3 "2015-09-12T12:46:01Z")

</div>

Awesome, thank you =) I will give it a whirl and report back!

---

<div class="post-metadata">

**Author:** ![reznorism](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@reznorism](https://forums.unrealengine.com/u/reznorism)\
**Post date:** [September 13, 2015, 4:33am UTC](https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937/4 "2015-09-13T04:33:42Z")

</div>

Having some serious trouble working this one out, any more help is appreciated =)

Basically, I have a merchant NPC in place that the player can buy/sell goods to. When they leave the merchant, it currently resets what he has for sale. But what I want to do, is save the date and time that they left the NPC (already doing) and if they come back and it’s been less than say 10 minutes the current inventory with the items the player sold are in it. But if its been more than 10 minutes, the merchants items have reset.

It’s to give the player an opportunity to re-buy items if they accidentally sold them.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_359f4d3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_359f4d3c](https://forums.unrealengine.com/u/anonymous_user_359f4d3c)\
**Post date:** [September 13, 2015, 10:42am UTC](https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937/5 "2015-09-13T10:42:23Z")

</div>

That’s probably easier using a _Timer_ node.

When your character leaves the shop start a Timer to call ResetInventory (or whatever) after 10 minutes (600 seconds) have passed. If the character returns while the timer is still running, stop the timer.

 ![58415-timers_in_ue49.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/1/e/c1e44e94ee05dad2e758346b4a0f9ce53019740c.png)

I haven’t actually used timers yet in Unreal 4.9, but the system looks fairly straightforward. In a quick test, I didn’t get any errors or warning trying to clear an uninitialized handle (when first entering the shop, the variable hasn’t been set yet).

If you need to save the timer to continue at the same time when loading a savegame, you can use _Get Timer Remaining Time_ and save the returned float value. Then when loading your savegame and this value is greater than zero, simply restart the timer (using _Set Timer By Event_) with the remaining time instead of the full 10 minutes.

![58416-timer_getremainingtime.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/2/5/92597f8d37fb32a509e95630bc7c4cb38a279070.png)

Good luck!

---

<div class="post-metadata">

**Author:** ![danielhsu129](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@danielhsu129](https://forums.unrealengine.com/u/danielhsu129)\
**Post date:** [February 13, 2025, 7:03pm UTC](https://forums.unrealengine.com/t/how-to-tell-how-much-time-has-passed/331937/6 "2025-02-13T19:03:44Z")

</div>

For those using Unreal Engine 5, you can now subtract two DateTime objects, which returns a TimeSpan object, which you can get total seconds from:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/8/a/98a26c7fe0646e12b49ca7d33569ce607cc83451.png)
