Function node problems

My brain must be getting old this friday.

Shouldn’t I be able to do this in a function node:

var date = payload.opc_to_db.record_date + “T” + payload.opc_to_db.record_time ;
date = new Date(date);
payload.data.myTimestamp = (date.getTime());

What error are you seeing?

payload.data.myTimestamp shows as null

Add console.log(date) to the 2nd line to see what your string is.

The likely issue is your date string not being valid. The below snippet also results in null on the payload:

payload.blah = (new Date('Bad')).getTime()
//payoad.blah = null

Here’s some info on what the JavaScript Date constructor will support:

If I use this it works:
var date = “06/28/2019 01:02:03” ;

If I use this it doesn’t:
var date = “06/28/2019” + " " + “01:02:03” ;

Can’t I add strings that way?

Those are equivalent. I see no issues.

It was the “T” inbetween date and time it didn’t like.
Just a space got it to work.

Yeah, the Date constructor is a bit picky on the formats it accepts. Glad we got it figured out!