I am just missing something and I can't seem to see it.
var now = new Date()
console.info("Now: " + now);
var fiveMinutesAgo = new Date()
fiveMinutesAgo.setMinutes(-5)
console.info("Filter by Date: " + fiveMinutesAgo);
var permitDateTime = new Date(el => el.DateCreated);
msg.payload = msg.payload.filter(el => el.DateCreated.includes(permitDateTime.getTime() < fiveMinutesAgo.getTime()))
return msg;
Put some debugging in using node.warn(). Like node.warn("permitDateTime"+permitDateTime) node.warn(el.DateCreated.includes(permitDateTime.getTime())
to get an idea of what the data actually is.
var now = new Date()
var fiveMinutesAgo = now.getTime() - (5*60000); //epoch minus 5 mins
msg.origPayload = msg.payload; //keep old one for reference / debugging
msg.fiveMinutesAgo = fiveMinutesAgo; //add ts it to msg so we can inspect it in a debug set to show complete message
msg.payload = msg.payload.filter(el => new Date(el.DateCreated).getTime() >= fiveMinutesAgo )
return msg;
EDIT...
let me explain this line msg.payload = msg.payload.filter(el => new Date(el.DateCreated).getTime() >= fiveMinutesAgo )
I have no idea what the type of el.DateCreated is. It could be a string, it could be a date object - BUT - to get you going, I am taking no chances, so, I create a new Date from whatever it is, then get its epoch, then compare it as a number to the fiveMinutesAgo variable.
note also, I add a few other items to the msg object - this is so I can view / debug the whole operation in the debug sidebar (set your debug to show complete message)
I will say one more thing - where are you getting this data? from a database? If so, you really should be doing this at the database side with a WHERE clause.