# Date management & debug message curious behavior?

**URL:** <https://discourse.nodered.org/t/date-management-debug-message-curious-behavior/30263>\
**Category:** General\
**Created:** [17 July 2020 12:45 UTC](https://discourse.nodered.org/t/date-management-debug-message-curious-behavior/30263 "2020-07-17T12:45:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![waquete](https://avatars.discourse-cdn.com/v4/letter/w/a698b9/32.png) [@waquete](https://discourse.nodered.org/u/waquete)\
**Post date:** [17 July 2020 12:45 UTC](https://discourse.nodered.org/t/date-management-debug-message-curious-behavior/30263/1 "2020-07-17T12:45:40Z")

</div>

Hi there!

I try to play with Date() inside a function block and found something curious...non blocking, but I would be happy to understand.

I need a timestamp in millisecond style (a non formatted integer) so I can easily compare or do some processing.

at first I tried this:

```auto
var test = new Date();
msg.payload = test;
return msg;

```

And output this on a debug box.  
debug windows shows:  
payload: "2020-07-17T12:39:02.927Z"

The date is written in read a looks like a formatted text output, so I thought I may not be able to use this for comparison or operation, but just in case, I tried this:

```auto
var test = new Date();
msg.payload = test - 3600000;
return msg;

```

This time the debug windows shows a numeric payload, written in blue:  
payload: 1594985920276  
I can click on the blue value to see different format like:  
payload: 2020-07-17T11:38:40.276Z

So it seems fine: I guess I can do what I need to do with my "test = new Date();".

But I wonder why it shows like a formatted string if I do not modify my value...?

---

<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:** [17 July 2020 12:48 UTC](https://discourse.nodered.org/t/date-management-debug-message-curious-behavior/30263/2 "2020-07-17T12:48:46Z")

</div>

Hi @waquete

When you do `var test = new Date()`, you are creating a new Date object. The Debug sidebar sees it is a Date object so displays it in a human readable format.

When you do `test - 360000` you are converting the Date object to a number - so the Debug sidebar displays it as a number. But the sidebar is a bit smarter than that and recognises that whilst it is a number, it is within a range of values that could be a Date - so will display it as a Date if you click on it.

---

<div class="post-metadata">

**Author:** ![waquete](https://avatars.discourse-cdn.com/v4/letter/w/a698b9/32.png) [@waquete](https://discourse.nodered.org/u/waquete)\
**Post date:** [17 July 2020 13:08 UTC](https://discourse.nodered.org/t/date-management-debug-message-curious-behavior/30263/3 "2020-07-17T13:08:15Z")

</div>

ahah this debug window is smarter than me 😄

Thanks for explanation, it's crystal clear now!

---

<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:** [31 July 2020 13:08 UTC](https://discourse.nodered.org/t/date-management-debug-message-curious-behavior/30263/4 "2020-07-31T13:08:24Z")

</div>

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