# Dates not handled correctly

**URL:** <https://discourse.nodered.org/t/dates-not-handled-correctly/61091>\
**Category:** General\
**Tags:** function-node\
**Created:** [11 April 2022 01:35 UTC](https://discourse.nodered.org/t/dates-not-handled-correctly/61091 "2022-04-11T01:35:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![killahbee](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@killahbee](https://discourse.nodered.org/u/killahbee)\
**Post date:** [11 April 2022 01:35 UTC](https://discourse.nodered.org/t/dates-not-handled-correctly/61091/1 "2022-04-11T01:35:20Z")

</div>

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.

```auto
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]
}

```

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [11 April 2022 01:48 UTC](https://discourse.nodered.org/t/dates-not-handled-correctly/61091/2 "2022-04-11T01:48:37Z")

</div>

> [@killahbee](#):
>
> `msg.payload.attributes.start_time`

what is this value ?

> [@killahbee](#):
>
> `(0 < datedif <= 1)`

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

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

} else {
    return [null, msg]
}

```

---

<div class="post-metadata">

**Author:** ![killahbee](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@killahbee](https://discourse.nodered.org/u/killahbee)\
**Post date:** [11 April 2022 09:37 UTC](https://discourse.nodered.org/t/dates-not-handled-correctly/61091/3 "2022-04-11T09:37:51Z")

</div>

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!!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 April 2022 09:38 UTC](https://discourse.nodered.org/t/dates-not-handled-correctly/61091/4 "2022-04-25T09:38:01Z")

</div>

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