Dates not handled correctly

Trying to get something done based on the date.
In this example the collection date is the 13th and today is the 10th, but for some reason it's is marking the if statement as true.

var now = new Date().getDate()
var collectday = new Date(msg.payload.attributes.start_time).getDate()
var datedif = collectday - now
if (0 < datedif <= 1) {
  return [msg, null]
} else {
  return [null, msg]
}

what is this value ?

This isn't valid, what are you trying do here ?
Why not just compare the dates

if (new Date().getDate() == new Date(msg.payload.attributes.start_time).getDate()) {
    return [msg, null]

} else {
    return [null, msg]
}

Ah so my math.

Basically what I am trying to do is to see if msg.payload.attributes.start_time is tomorrow, if it is tomorrow than I have other stuff in my flow, if not it will go to the second output that goes no where.

So I think I am going to go with something like yours, I'll just do -1 to the collection date then check if they are equal instead.

EDIT: Yep that worked!! Thank you!!

1 Like

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