# Timestamp in function problems

**URL:** <https://discourse.nodered.org/t/timestamp-in-function-problems/34638>\
**Category:** General\
**Created:** [21 October 2020 14:19 UTC](https://discourse.nodered.org/t/timestamp-in-function-problems/34638 "2020-10-21T14:19:08Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 October 2020 20:27 UTC](https://discourse.nodered.org/t/timestamp-in-function-problems/34638/10 "2020-10-21T20:27:10Z")

</div>

As informed by @Paul-Reed the change node has $moments() in the JSONata expression.  
e.g.

```auto
[{"id":"c7fe2615.e38278","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20201015120000","payloadType":"str","x":220,"y":1960,"wires":[["e23e595e.a3d348"]]},{"id":"e23e595e.a3d348","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(\t $currentTime := $moment().tz('Europe/London').format();\t $duration := $moment(payload,'YYYYMMDDHHmmss').fromNow($currentTime);\t {\t \"current\": $currentTime,\t \"duration\": $duration\t }\t)\t\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":1960,"wires":[["49952583.65b3fc"]]},{"id":"49952583.65b3fc","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":1960,"wires":[]}]

```

> [@Formatting times & dates with moment.js examples](https://discourse.nodered.org/t/formatting-times-dates-with-moment-js-examples/29553):
>
> Since node-RED v1.1.0 support for the moment.js date/time library has been added, currently only available for jsonata expressions, but hopefully in time to also be added to the function node. I've included a few examples below, of how Moment can be used to provide date/time functions. Please feel free to add others This is the basic format, which creates a realtime UTC timestamp similar to Sun Jul 05 2020 13:22:30 GMT+0000. [moment] [{"id":"54c46ebe.3b623","type":"change","z":"a444a9ff.e7a…

---

_[View the full topic](https://discourse.nodered.org/t/timestamp-in-function-problems/34638)._
