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

**URL:** https://discourse.nodered.org/t/errors-when-trying-to-compare-dates-every-5s-function-tried-to-send-a-message-of-type-string/11028
**Category:** General
**Created:** [11 May 2019 18:03 UTC](https://discourse.nodered.org/t/errors-when-trying-to-compare-dates-every-5s-function-tried-to-send-a-message-of-type-string/11028 "2019-05-11T18:03:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![xoani](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xoani/32/7844_2.png) [@xoani](https://discourse.nodered.org/u/xoani)
#### Post date: [11 May 2019 18:03 UTC](https://discourse.nodered.org/t/errors-when-trying-to-compare-dates-every-5s-function-tried-to-send-a-message-of-type-string/11028/1 "2019-05-11T18:03:17Z")

</div>

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:

```auto
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:

```auto
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:

```auto
"Function tried to send a message of type string"

```

Can anyone offer any guidance¿?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [11 May 2019 20:59 UTC](https://discourse.nodered.org/t/errors-when-trying-to-compare-dates-every-5s-function-tried-to-send-a-message-of-type-string/11028/2 "2019-05-11T20:59:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [12 May 2019 05:13 UTC](https://discourse.nodered.org/t/errors-when-trying-to-compare-dates-every-5s-function-tried-to-send-a-message-of-type-string/11028/3 "2019-05-12T05:13:44Z")

</div>

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
