# Arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type

**URL:** <https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442>\
**Category:** General\
**Created:** [27 June 2023 14:57 UTC](https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442 "2023-06-27T14:57:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfuchs1987](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tfuchs1987/32/44508_2.png) [@tfuchs1987](https://discourse.nodered.org/u/tfuchs1987)\
**Post date:** [27 June 2023 14:57 UTC](https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442/1 "2023-06-27T14:57:15Z")

</div>

Hi Forum,

I have a function node with the following code which runs fine and does what I want. msg.date contains a timestamp.

```auto
let age = (new Date() - new Date(msg.date)) / (1000 * 60);

```

but since the new Node-RED update I receive the following error-messages

```auto
"new Date()" is marked with this error:
The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.(2362)

"new Date(msg.date)" is marked with this one:
The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.(2363)

```

Any advice is appreciated on why this code is bad. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 June 2023 15:10 UTC](https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442/2 "2023-06-27T15:10:17Z")

</div>

The syntax checker does not understand that if you perform arithmetic on a Date object then javascript will automatically call getTime() for you to convert the dates to milliseconds. If you explicitly do the conversion then it should be happy  
`let age = (new Date().getTime() - new Date(msg.date).getTime()) / (1000 * 60)`

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 June 2023 15:15 UTC](https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442/3 "2023-06-27T15:15:07Z")

</div>

Alternatively try

```auto
let age = (new Date().valueOf() - new Date(msg.date).valueOf()) / (1000 * 60);

```

---

<div class="post-metadata">

**Author:** ![tfuchs1987](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tfuchs1987/32/44508_2.png) [@tfuchs1987](https://discourse.nodered.org/u/tfuchs1987)\
**Post date:** [27 June 2023 15:22 UTC](https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442/4 "2023-06-27T15:22:33Z")

</div>

thank you guys! Both solutions work, I think 🍻

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [27 June 2023 15:26 UTC](https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442/5 "2023-06-27T15:26:36Z")

</div>

> [@tfuchs1987](#):
>
> `let age = (new Date() - new Date(msg.date)) / (1000 * 60)`

or

```auto
let age = (Date.now() - new Date(msg.date).getTime()) / (1000 * 60)

```

---

<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:** [11 July 2023 15:27 UTC](https://discourse.nodered.org/t/arithmetic-operation-must-be-of-type-any-number-bigint-or-an-enum-type/79442/6 "2023-07-11T15:27:20Z")

</div>

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