Errors when trying to compare dates (every 5s) :"Function tried to send a message of type string"

Hello. I need to be able to check when the date changes (when the day is over and a new one starts) ever 5 seconds. For that I have a function node that checks the date and saves it in a msg.var , another delay node for 5s and another function node that gets the date again and compares it to the one saved in msg. var. At least that is what I WANTED to do, but I keep getting errors.

This is my first function node:

var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
msg.var=date
return msg;

Then I have 5 seconds of delay and the next function node:

var today = new Date();
var newdate = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();


if (msg.var == newdate){
    return [0,0]}

else{

    return[msg, 0]}

I keep getting this error message in the FIRST function node and the flow stops because of it:

"Function tried to send a message of type string"

Can anyone offer any guidance¿?

You get this error because you are not sending payload, but msg.var and your debug node wants to display msg.payload by default.

Change the debug node to complete msg object or msg.var and the error will disappear.

The msg you return must be an object, so your second function can't just return 0. It must be return [{payload:0},{payload:0}] etc or null if you need no output