# Timestamp wont update

**URL:** https://discourse.nodered.org/t/timestamp-wont-update/40710
**Category:** Dashboard
**Created:** [10 February 2021 00:26 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710 "2021-02-10T00:26:10Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Chumbo](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Chumbo](https://discourse.nodered.org/u/Chumbo)
#### Post date: [10 February 2021 00:26 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/1 "2021-02-10T00:26:11Z")

</div>

Hello!

I have a couple of watch nodes to watch an excel spreadsheet that is automatically updating every hour.This part works fine, but i am also trying to grab that time, when it updates, to populate a field on the dashboard.

I want it to it grab and displays the newly updated data, and also show 'date of last update' date and time so we know its all current. this is the part that's not working. when i click the inject node manually it updates the time and date displayed, but it is not being triggered when the watch nodes trigger every hour.

any ideas why this is not working?

thanks,

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

---

<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: [10 February 2021 01:14 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/2 "2021-02-10T01:14:16Z")

</div>

Why not add a `change` node into the flow and have it set some thing like msg.current\_time to the current timestamp. Then you can use that as the update time.

---

<div class="post-metadata">

### Author: ![ryan780](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ryan780/32/22974_2.png) [@ryan780](https://discourse.nodered.org/u/ryan780)
#### Post date: [10 February 2021 03:19 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/3 "2021-02-10T03:19:59Z")

</div>

I am doing this with a few different data logging flows. The easiest way I have found to do it is to use the Date/Time Formmatter node to format the date time to the way that I want it, and to move it into msg.timestamp. You can then use it whereever you want and it's formatted the way you want it too. I also use it to display "last update" on dashboard nodes by formatting to something shorter. It accepts any format you can set up in moment.

[{"id":"a3184d85.bb296","type":"moment","z":"3705f614.803cfa","name":"Test","topic":"","input":"","inputType":"date","inTz":"America/New\_York","adjAmount":"0","adjType":"hours","adjDir":"subtract","format":"YYYY-MM-DDTHH:mm:ss","locale":"C","output":"timestamp","outputType":"msg","outTz":"America/New\_York","x":830,"y":460,"wires":[["4b038ad2.556414"]]}]

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/e/be5ac2a6324ed72aa2a833374f317bee5bb589c2.png)

---

<div class="post-metadata">

### Author: ![Chumbo](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Chumbo](https://discourse.nodered.org/u/Chumbo)
#### Post date: [11 February 2021 02:00 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/4 "2021-02-11T02:00:07Z")

</div>

Thanks for your reply. I am very new to node-red, trying to adapt / fix work done by a colleague.  
i can't get your idea to work, can you explain further?

how to assign the current time stamp to another variable?  
how to format the output to read well, at the moment its just outputting a string of numbers.

---

<div class="post-metadata">

### Author: ![Chumbo](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Chumbo](https://discourse.nodered.org/u/Chumbo)
#### Post date: [11 February 2021 02:00 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/5 "2021-02-11T02:00:51Z")

</div>

Thanks for your reply. I am very new to node-red, trying to adapt / fix work done by a colleague.  
i can't get your idea to work, can you explain further?

how to move it to msg.timestamp and display?

---

<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: [11 February 2021 02:05 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/6 "2021-02-11T02:05:54Z")

</div>

Since you are new to Node-RED, I suggest you spend an hour wathching the [Node-RED Essentials](https://www.youtube.com/channel/UCQaB8NXBEPod7Ab8PPCLLAA) YouTube videos put out by the developers, It will be worth the time to get familiar with Node-RED.

Once you have watched them, if you still have problems let me know,

---

<div class="post-metadata">

### Author: ![Chumbo](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Chumbo](https://discourse.nodered.org/u/Chumbo)
#### Post date: [11 February 2021 20:51 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/7 "2021-02-11T20:51:07Z")

</div>

Good point.

I've watched a bit so far, trying to do the simple example but the 'cost' is not joining on at the end, but its showing in the debug output if you connect it after the function node. why!? my flow below.

```auto
[{"id":"42deaea0.1a83d","type":"inject","z":"fcad3fcc.66506","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":400,"wires":[["54755ead.d6145"]]},{"id":"54755ead.d6145","type":"template","z":"fcad3fcc.66506","name":"csv data","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Date,Quantity,Item\n2019-12-01,1,Apple\n2019-12-02,2,Orange\n2019-12-02,1,Pear\n2019-12-03,3,Banana\n2019-12-03,2,Apple\n2019-12-04,1,Pear","output":"str","x":430,"y":400,"wires":[["b6037b09.1fb758"]]},{"id":"b6037b09.1fb758","type":"csv","z":"fcad3fcc.66506","name":"","sep":",","hdrin":true,"hdrout":"all","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":620,"y":420,"wires":[["8b5b71ec.a4113"]]},{"id":"7dde0f94.4122e","type":"function","z":"fcad3fcc.66506","name":"add cost","func":"var PRICES = {\n \"Apple\": 10,\n \"Orange\":20,\n \"Pear\":50,\n \"Banana\":30\n}\n\nmsg.payload.cost = msg.payload.Quantity * PRICES[msg.payload.Item]\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":540,"wires":[["f86311c6.d9ffc"]]},{"id":"f86311c6.d9ffc","type":"join","z":"fcad3fcc.66506","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":760,"y":560,"wires":[["5f788dff.883c34"]]},{"id":"8b5b71ec.a4113","type":"split","z":"fcad3fcc.66506","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":920,"y":440,"wires":[["7dde0f94.4122e"]]},{"id":"5f788dff.883c34","type":"csv","z":"fcad3fcc.66506","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":950,"y":560,"wires":[["3a4ff9fe.2893e6"]]},{"id":"3a4ff9fe.2893e6","type":"debug","z":"fcad3fcc.66506","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":560,"wires":[]}]

```

---

<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: [11 February 2021 23:00 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/8 "2021-02-11T23:00:02Z")

</div>

Ok, lets work this thru one step at a time.

First copy your 'css data `template` node off to the side and edit the node so you only send it one roe - this will make looking at the debug easier.

Put a `debug` node (set to display the 'Complete msg object') on the output of the `split`, the `function', the `join`and the`csv` nodes.

What do you notice?

---

<div class="post-metadata">

### Author: ![Chumbo](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Chumbo](https://discourse.nodered.org/u/Chumbo)
#### Post date: [12 February 2021 01:40 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/9 "2021-02-12T01:40:11Z")

</div>

Everything works up until the csv node at the end.

the debug from the output of the 'join' node is showing an output array, containing all the items, each with the 'cost' field added in. but when it goes through the next 'csv' node it outputs without the 'cost' included....

---

<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: [12 February 2021 08:45 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/10 "2021-02-12T08:45:23Z")

</div>

Great you have isolated the issue! Now hat does the cvs node help say about how it works?

---

<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: [12 February 2021 09:52 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/11 "2021-02-12T09:52:44Z")

</div>

I just looked at the 'Help' for the `CSV` node and I see it isn't clear (I'll offer a PR to make the explaination clearer)

When a input is a JavaScript object it tries to build a CSV string, it uses one of two things to control what the output looks like. (1) it uses the `Columns` property of the node  
 ![Screen Shot 2021-02-12 at 4.48.19 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64e7aeda39169fcea5828979c025853ee096e132.png)  
or it uses msg.columns of the incoming msg  
 ![Screen Shot 2021-02-12 at 4.48.57 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/2/72d0d538b85cc00798f13efc5477e2d04da09bb7.png)

Since you haven't added 'cost' to the list of columns to create, it doesn't create them.

Add this line just before the `return msg` line in your function and you should see it work:

```auto
msg.columns += ",cost"

```

---

<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: [14 March 2021 09:53 UTC](https://discourse.nodered.org/t/timestamp-wont-update/40710/12 "2021-03-14T09:53:08Z")

</div>

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