How to append timestamp into msg.payload


Hello Everyone,
I am using node-red-contrib-moment and I am using date/time formatter my problem is when i am using output as msg.payload then my original message get replaced by the time. So I want to add timestamp with my original message but I also want to change the format of time.
Please help.




Use a change node to move your msg.payload to something else before using the node.

After the moment node you can then create a new msg.payload from both parts.



Another option in addition to ukmoose's solution is to put the time to some other property like msg.time, then pass through to a template node with something along the lines of {{payload}} {{time}}outputting to msg.payload.



but if i change my msg.payload to string then how can i use it in function because i want to append the time with my original messsage.



Without an example of a message it is difficult to advise as thats the first time you mentioned that msg.payload wasn't a string. Please give an example of your msg object now and what you want it to be.



Okay so the original message is json file whcih consits of some number like this [0,15.3596,207.2841,0,1.88446,251.91855] so this is the msg.payload right. But when I am using moment and also change node then I am confused that what will go in that change node because in change node there are two fields "set" and "to". So if i set it to msg.payload as you said earlier then what will be "to" field and how I am going to use that in function because i want to append my original message+formatted timestamp([0,15.3596,207.2841,0,1.88446,251.91855] 2019-01-18T18:35:31.253Z) i want something like this



[0,15.3596,207.2841,0,1.88446,251.91855] isn't a number, if it has quotes around it it is a string, otherwise it is an array

The change node has more options than just set
There are 4 options set``,`change,delete&move```

You can move msg.payload to

Then when the moment node writes to msg.payload it won't overwrite your data.

It would then be worth you doing some reading on javascript data types which should lead you to the answer of the next part of your question



Just use a different output property like msg.time - moment lets you do that.

Or make your payload an object and add the time into the object with msg.payload.time or some such.

moment is very flexible so you can do whatever you want.