# New date() bug?

**URL:** <https://discourse.nodered.org/t/new-date-bug/66149>\
**Category:** General\
**Created:** [7 August 2022 21:20 UTC](https://discourse.nodered.org/t/new-date-bug/66149 "2022-08-07T21:20:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/draax/32/65896_2.png) [@Draax](https://discourse.nodered.org/u/Draax)\
**Post date:** [7 August 2022 21:20 UTC](https://discourse.nodered.org/t/new-date-bug/66149/1 "2022-08-07T21:20:41Z")

</div>

Hi!

Im very new to Node-Red and are trying to create a function.

My code looks like this:

let startDate = new Date(2022,8,7,0,0,0,0);

node.warn(["your\_variable=", startDate]);

the debug log output is this:

2022-09-06T22:00:00.000Z

While im expecting it to be 2022-08-07T00:00:00.000Z

Im using Home assistant OS on a Raspberry Pi 4 and the location settings are correct.

Any idea?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [7 August 2022 21:40 UTC](https://discourse.nodered.org/t/new-date-bug/66149/2 "2022-08-07T21:40:38Z")

</div>

Hi @Draax

The `new Date(...)` function expects a `monthIndex`, which starts at `0` for January. So passing in an `8` as you are, actually means September.

As for the hours - the function creates the time in the timezone of the device its running on. If you are passing in `00:00:00` as the time, the fact it results in `22:00:00Z` suggests you are in a `GMT+2` location.

---

<div class="post-metadata">

**Author:** ![Draax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/draax/32/65896_2.png) [@Draax](https://discourse.nodered.org/u/Draax)\
**Post date:** [7 August 2022 22:45 UTC](https://discourse.nodered.org/t/new-date-bug/66149/3 "2022-08-07T22:45:53Z")

</div>

Hi @knolleary,  
Much appreciated for your feedback!

I understand the month index part but if possible could you please provide me an example of how I could achieve creating a starting date of today with the hours 00:00:00?

---

<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:** [7 August 2022 22:51 UTC](https://discourse.nodered.org/t/new-date-bug/66149/4 "2022-08-07T22:51:51Z")

</div>

try without the time ie =new Date(2022, 7, 7)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 August 2022 06:24 UTC](https://discourse.nodered.org/t/new-date-bug/66149/5 "2022-08-08T06:24:56Z")

</div>

Do you want midnight local time or midnight UTC?

---

<div class="post-metadata">

**Author:** ![eksij](https://avatars.discourse-cdn.com/v4/letter/e/9de053/32.png) [@eksij](https://discourse.nodered.org/u/eksij)\
**Post date:** [13 August 2022 05:18 UTC](https://discourse.nodered.org/t/new-date-bug/66149/6 "2022-08-13T05:18:07Z")

</div>

Your new Date (2022, 8, 7, 0, 0, 0, 0); What you get is a Date instead of a str and your time zone ratio is +2. It is recommended to use moment to solve it. This module is very powerful

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 August 2022 07:52 UTC](https://discourse.nodered.org/t/new-date-bug/66149/7 "2022-08-13T07:52:48Z")

</div>

It seems that @Draax has lost interest in the question.

---

<div class="post-metadata">

**Author:** ![Draax](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/draax/32/65896_2.png) [@Draax](https://discourse.nodered.org/u/Draax)\
**Post date:** [13 August 2022 20:18 UTC](https://discourse.nodered.org/t/new-date-bug/66149/8 "2022-08-13T20:18:23Z")

</div>

Apologize for late response, thanks everyone for the input!  
@knolleary 's answer resolved everything 🙂

---

<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:** [27 August 2022 20:18 UTC](https://discourse.nodered.org/t/new-date-bug/66149/9 "2022-08-27T20:18:34Z")

</div>

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