# How to write a DateTime with an Action Node

**URL:** <https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250>\
**Category:** General\
**Created:** [9 October 2024 00:32 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250 "2024-10-09T00:32:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![steerage250](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steerage250/32/38999_2.png) [@steerage250](https://discourse.nodered.org/u/steerage250)\
**Post date:** [9 October 2024 00:32 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250/1 "2024-10-09T00:32:40Z")

</div>

I'm trying to write to a input\_datetime helper with an Action node - but keep getting "HomeAssistantError: extra keys not allowed @ data['value']". I really don't get JavaScript.

The data coming from the node prior to the Action node is:  
msg : Object  
{ \_msgid: "3d6978f0f9f965bd", payload: "2024-10-07T16:00:00+08:00", topic: "", data: object }

So I think the payload has the date and time correct - but how do I write the Action node to write it to the datetime helper?

this doesn't work ☹

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/00e2bb4dd83aa5c42197da823c3e8bf71534f48c.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [9 October 2024 05:51 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250/2 "2024-10-09T05:51:30Z")

</div>

well the `"msg.payload"` (with the double quotes) won't work as it becomes a literal string, ie. remove the double quotes.

This sounds specific to home assistant. There are not many HA users here.  
Did you try the suggestions at the 'looking for help' section ?

---

<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:** [9 October 2024 06:08 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250/3 "2024-10-09T06:08:18Z")

</div>

Have you tried just select `msg.` and typing `payload` in data field.

Or

If an object with property `value` is required.  
Select `J: expression` and enter

```auto
{"value": $$.payload}

```

[edit] fixed typo.

---

<div class="post-metadata">

**Author:** ![steerage250](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steerage250/32/38999_2.png) [@steerage250](https://discourse.nodered.org/u/steerage250)\
**Post date:** [9 October 2024 07:53 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250/4 "2024-10-09T07:53:21Z")

</div>

thanks, but no luck.

sounds like I'll need to try a Home Assistant-related NodeRed group

---

<div class="post-metadata">

**Author:** ![mikefila](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mikefila/32/95223_2.png) [@mikefila](https://discourse.nodered.org/u/mikefila)\
**Post date:** [9 October 2024 15:47 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250/5 "2024-10-09T15:47:35Z")

</div>

If we look at the documentation at the bottom of the node we see:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a927d71cf0789374c8f1da424cd8423a58667834.png)

So first the key is not `value` but one of the three above depending on the type of date/time you need to pass.

If we also look at the format of the actual value, it does not show iso datetime input, we need to format the value. Set the data field to `J:Expression`.

```auto
{"datetime":$moment(payload).format("YYYY-MM-DD hh:mm:ss")}

```

---

<div class="post-metadata">

**Author:** ![steerage250](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steerage250/32/38999_2.png) [@steerage250](https://discourse.nodered.org/u/steerage250)\
**Post date:** [10 October 2024 00:24 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250/6 "2024-10-10T00:24:46Z")

</div>

oh fantastic - worked a treat! Thank you so much. I keep learning (sadly, not quick-enough).

---

<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:** [8 January 2025 00:25 UTC](https://discourse.nodered.org/t/how-to-write-a-datetime-with-an-action-node/92250/7 "2025-01-08T00:25:39Z")

</div>

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