Msg.payload timestamp

Node-Red time stamps messages; how can this timestamp be accessed using JS in a function node?
Is the something like this var T=msg.payload.time()?

Thanks X

There is no timestamp in the message unless you add one. Prior to the node use a change node and set msg.payload.timestamp to timestamp

Not generally it doesn't. But if you do have a javascript timestamp in msg.payload (from an Inject node for example) then you can to
const T = new Date(msg.payload)

See JavaScript Date Objects for the what you can then do with a Date object. Do not be too quick to format it as a text date, it is best to leave formatting it until you need to display it or need it as a string for some other reason.

I guess what confused me was the timestamp displayed by the "Debug" node. I was thinking that any received message was automatically timestamped; apparently it's the "Debug" node that just displays a timestamp.

The debug node will only display a timestamp if that is what is in the message. What are you feeding into the debug node? If it is from an Inject node then double click the inject node and see how you have configured it.

The debug node does display a timestamp but that is created by the debug node, it is not part of the msg.

image

TotallyInformation, That is what I've come to understand. However, I'm receiving messages via MQTT, perhaps MQTT is also timestamping the messages.

If so, then the question is how can I use JS in a function node to extract that property from msg.payload?

No, it isn't.

You haven't shared with us any example data and therefore we cannot help further until you do. Anything at this point would be a guess.

I understand; I guess the only issue is does MQTT timestamp it's messages and what does Node-Red do (or do not do) with that data?
Perhaps, at least in-part this is a question for the MQTT forum.

Oh yes, that timestamp. I was thrown by the suggestion that it is in the payload.

1 Like

Repeating the answer - no.

Nothing, because that data does not exist and even if it did, Node-RED would do nothing with it unless you instructed it to.

Well, go ahead if you don't like my answers but you won't get a different answer.

Not sure why you are finding it difficult to understand what we are saying? It is easy enough to prove for yourself. THERE IS NO TIMESTAMP added to the msg by Node-RED or MQTT unless you or some other node/device/service adds it.

Sorry there, it's not that I don't like your answers, I missed your first answer that MQTT doesn't timestamp. That's the only reason I was going to post on the MQTT forum.

I've resolved the issue I was having farther up the data-stream, in my gateway.

Thank's for your informative information; even if I failed to read it. :blush:

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