# Is it possible to use \`$moment.duration()\` in JSONata?

**URL:** <https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752>\
**Category:** General\
**Created:** [8 September 2026 05:52 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752 "2026-09-08T05:52:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![EasyPi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/easypi/32/108344_2.png) [@EasyPi](https://discourse.nodered.org/u/EasyPi)\
**Post date:** [8 September 2026 05:52 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752/1 "2026-09-08T05:52:12Z")

</div>

I want to show uptime in [humanized](https://momentjs.com/docs/#/durations/humanize/) format: `168732000 -> 2 days`

❌ Invalid JSONata expression:

```js
$moment.duration(168732000).humanize()

```

✔ It works:

```js
$moment(168732000).to(0, true)

```

It seems that `$moment.function()` is not allowed in JSONata:

- `moment.duration()`
- `moment.unix()`
- `moment.months()`
- `moment.weekdays()`
- `moment.isMoment(obj)`
- `moment.isDate(obj)`

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 September 2026 07:14 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752/2 "2026-09-08T07:14:16Z")

</div>

This is the documentation for JSONata date/time functions

> **[Date/Time functions · JSONata](https://docs.jsonata.org/date-time-functions)**
>
> \## \`$now()\`

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [8 September 2026 07:39 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752/3 "2026-09-08T07:39:36Z")

</div>

and See this thread - [Problems with JSONata in Node-RED](https://discourse.nodered.org/t/problems-with-jsonata-in-node-red/101734)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [8 September 2026 10:57 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752/4 "2026-09-08T10:57:37Z")

</div>

There should be a humanise node in the node-red-contrib-moment package.

---

<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:** [8 September 2026 14:18 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752/5 "2026-09-08T14:18:57Z")

</div>

It would appear that the duration function and its sub functions are not working in JOSNata. Tested on 4.1.8

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [8 September 2026 14:28 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752/6 "2026-09-08T14:28:35Z")

</div>

This is because we expose the `$moment()` function, _not_ the top level `moment` object that has the `duration` function hanging under it.

So to answer the question directly - no it isn't possible today.

Please considering raising an issue and we can look if its possible to add support. Although the whole `moment` library is no longer maintained so not sure how much we want to expand use of it if there are better alternatives.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 September 2026 14:29 UTC](https://discourse.nodered.org/t/is-it-possible-to-use-moment-duration-in-jsonata/101752/7 "2026-09-22T14:29:09Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
