How to use two object values (date and time) to make timestamp

I have a msg with date and time separated in two elements, and I want to merge tha values from these two to be able to output a timestamp. Anybody know how I can make that happen in a function node?

msg.payload.originalDate: "2021-10-30"
msg.payload.originalTime: "21:30:00.000"
I want to use these values to output this timestamp 1635622200000

Here was my first try and of course it didn't work, but hopefully it shows what I want to accomplish.

var date = msg.payload.originalDate
var time = msg.payload.originalTime
var alarm = new Date(date, "T", time)

var msg2 = {payload: alarm.getTime()};

With this configuration instead of the one above
var alarm = new Date(date)
I get a timestamp output, but I just can't figure out how to get the time in there aswell.

var alarm = new Date(date + "T" + time)

You need to concatenate the strings

1 Like

So close, but still so far away :laughing:
With your help I finally got the result I wanted, thank you very much.

1 Like

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