# Trying to add timestamp to output of ping

**URL:** <https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083>\
**Category:** General\
**Created:** [2 January 2023 22:49 UTC](https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083 "2023-01-02T22:49:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clutch](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@Clutch](https://discourse.nodered.org/u/Clutch)\
**Post date:** [2 January 2023 22:49 UTC](https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083/1 "2023-01-02T22:49:24Z")

</div>

I'm working on my second flow ever. Trying to add a timestamp to output of ping before I store it in a file. What did I do wrong?

Node Red v3.0.2 running on a Pi2.

Thanks,

```auto
[
    {
        "id": "99ef514ed8f83fb0",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "f9bf451785ed5e44",
        "type": "ping",
        "z": "99ef514ed8f83fb0",
        "protocol": "IPv4",
        "mode": "timed",
        "name": "IsMyPhoneHome",
        "host": "192.168.1.129",
        "timer": "60",
        "inputs": 0,
        "x": 200,
        "y": 120,
        "wires": [
            [
                "26eb2ed06669929e"
            ]
        ]
    },
    {
        "id": "02821fe1a125e4f1",
        "type": "debug",
        "z": "99ef514ed8f83fb0",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 120,
        "wires": []
    },
    {
        "id": "8422207d09edcb9d",
        "type": "file",
        "z": "99ef514ed8f83fb0",
        "name": "PhoneHome",
        "filename": "/home/pi/phonehome.txt",
        "filenameType": "str",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 570,
        "y": 120,
        "wires": [
            [
                "02821fe1a125e4f1"
            ]
        ]
    },
    {
        "id": "26eb2ed06669929e",
        "type": "function",
        "z": "99ef514ed8f83fb0",
        "name": "AddTime2",
        "func": "msg.payload.Time = new Date()\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 380,
        "y": 120,
        "wires": [
            [
                "8422207d09edcb9d"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 January 2023 01:31 UTC](https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083/2 "2023-01-03T01:31:29Z")

</div>

In your function node msg.payload is a string but you are trying to use it as an object. One way to do this would be to use a `change` node to convert msg.payload to an object and add the time to like this:

![Screenshot 2023-01-02 at 8.28.53 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83ed456ceeee4e69e9915a01c6337ca0462caf02.png)

You should do a google search using 'javascript what is an object' and do some learning 🙂

---

<div class="post-metadata">

**Author:** ![Hubertus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hubertus/32/10077_2.png) [@Hubertus](https://discourse.nodered.org/u/Hubertus)\
**Post date:** [3 January 2023 08:09 UTC](https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083/3 "2023-01-03T08:09:08Z")

</div>

you could also use the node '[node-red-contrib-simpletime](https://flows.nodered.org/node/node-red-contrib-simpletime)'. This inserts the desired times/date configurable.

BR  
Hubertus

---

<div class="post-metadata">

**Author:** ![Clutch](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@Clutch](https://discourse.nodered.org/u/Clutch)\
**Post date:** [3 January 2023 23:00 UTC](https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083/4 "2023-01-03T23:00:12Z")

</div>

Thank you for helping. I think that inserts epoch or unix time. It worked. I know I have a lot to learn but I'm retiring soon and I'll have time.

---

<div class="post-metadata">

**Author:** ![Clutch](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@Clutch](https://discourse.nodered.org/u/Clutch)\
**Post date:** [3 January 2023 23:00 UTC](https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083/5 "2023-01-03T23:00:43Z")

</div>

I did not try it yet, but I see it gives me some options.

Thanks,

---

<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:** [4 March 2023 23:01 UTC](https://discourse.nodered.org/t/trying-to-add-timestamp-to-output-of-ping/73083/6 "2023-03-04T23:01:11Z")

</div>

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