# System date/time in canister update functions

**URL:** <https://forum.dfinity.org/t/system-date-time-in-canister-update-functions/9327>\
**Category:** Developers\
**Created:** [December 4, 2021, 8:47pm UTC](https://forum.dfinity.org/t/system-date-time-in-canister-update-functions/9327 "2021-12-04T20:47:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 4, 2021, 8:47pm UTC](https://forum.dfinity.org/t/system-date-time-in-canister-update-functions/9327/1 "2021-12-04T20:47:01Z")

</div>

In a typical Web2 update endpoint, the system date/time of the application server will be used to set a timestamp with the saved record.

Since Internet Computer updates run on all nodes in the subnet to reach a two thirds consensus, and each node may run the function at different times, and the times are not guaranteed to be the same on all nodes, it does not appear that the result of an update function can be deterministic when including the side-effect of a system date/time.

My solution at the moment is as follows:

1. Expose a public query function that returns the system epoch time (Time.now()) from the single node/canister that executes the function.
2. Call the query function from the front-end to retrieve the node’s epoch time.
3. Include the epoch time from the query function in the payload to the update function.
4. In the update function, validate that the time provided is within _n_ seconds of the current epoch time, since each canister executing the function may differ slightly and some time must be allotted for the network calls.

Note that I do not want to rely on the users’ system times since those times can be tampered with.

Is this a necessary workflow to include timestamps with saved records or is there a better way? Thanks!

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [December 5, 2021, 8:26am UTC](https://forum.dfinity.org/t/system-date-time-in-canister-update-functions/9327/2 "2021-12-05T08:26:41Z")

</div>

The IC system provides a deterministic “now” timestamp. Why is that not sufficient?

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 5, 2021, 4:55pm UTC](https://forum.dfinity.org/t/system-date-time-in-canister-update-functions/9327/3 "2021-12-05T16:55:21Z")

</div>

Thank you. I just wasn’t aware that it was deterministic. I would love to know the concepts used to achieve determinism when each replica runs the code at different times. Is that what [the documentation](https://smartcontracts.org/docs/base-libraries/Time.html) means by the following statement?

“within an invocation of one entry point, the time is constant.”

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [December 5, 2021, 5:44pm UTC](https://forum.dfinity.org/t/system-date-time-in-canister-update-functions/9327/4 "2021-12-05T17:44:25Z")

</div>

The time is simply the time of the block that causes the message to be executed, and thus deterministic.

Now you might say “but I need the time when the actual execution happens”. And then I would say that you probably don’t, and really there is no point in distinguishing between the various points in time before an action was _caused_ and when its effects become observable. That the various replicas might execute the message at slightly different times is really quite irrelevant then.

---

<div class="post-metadata">

**Author:** ![Motokoder](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@Motokoder](https://forum.dfinity.org/u/Motokoder)\
**Post date:** [December 5, 2021, 5:46pm UTC](https://forum.dfinity.org/t/system-date-time-in-canister-update-functions/9327/5 "2021-12-05T17:46:12Z")

</div>

Brilliant! Thank you so much for that explanation!
