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.

Thanks,
Gaurav

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.

1 Like

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 msg.data

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.

I am wondering what ukmoose thinks to accomplish with his comment 'do your homework'.
I had the same question, googled and landed here. Just an snwer: this is how you do such stuff would have helped more people. Sometimes a maker want to make something and stumbles on a whole new world. Why do a lot of people replying in fora think they are the bigger one who have to point the noob it's place?
If your car brakes down, you expect the garage to send you to the manufacturer for a in-depth course in car mechanics? Or would it help you if he just advised yoy ti clean the spark plugs?

No, you expect to pay a significant amount of money so he/she fixes it for you. If you ask a garage for help but you are not prepared to pay then you are likely to be disappointed.
The idea here is that people learn from others. Very often the best way to learn is to be pointed in the right direction and told where to read up on something in order to be able to find a solution. If the OP had come back and said he did not understand something then further help would have been forthcoming.
If you still have a problem then it would be best to start a new thread, explaining exactly what the problem is and no doubt someone will do their best to assist.

2 Likes

"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin

4 Likes