# Get nice Date-Format from Timeseries?

**URL:** <https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208>\
**Category:** Dashboard\
**Created:** [24 February 2020 18:03 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208 "2020-02-24T18:03:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [24 February 2020 18:03 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/1 "2020-02-24T18:03:49Z")

</div>

Hello,

I would like to fill my dashboard with daily values for 200 days.  
The values have a timestamp in the ms-format 1579046400000.  
Unfortunately this format is total unreadable for a bar chart and too long.

Is it possible to convert into a nice date-format like 20200224 ? or 200224 ?

BR

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 February 2020 18:14 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/2 "2020-02-24T18:14:53Z")

</div>

node-red-contrib-moment

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [24 February 2020 18:16 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/3 "2020-02-24T18:16:59Z")

</div>

I have this package installed but I do not get the expected output

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [24 February 2020 18:29 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/4 "2020-02-24T18:29:50Z")

</div>

I get the time as an integer from the previous node:

x.timestamp = parseInt(msg.payload.Timeseries);

what can I do to get a nice date format ?

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [24 February 2020 18:53 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/5 "2020-02-24T18:53:49Z")

</div>

I searched for a ms-format time and didn't find any information, what kind of timestamp is that? Is it epoch time?

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [24 February 2020 18:56 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/6 "2020-02-24T18:56:46Z")

</div>

its the format of the time in miliseconds: 1579046400000

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [24 February 2020 19:01 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/7 "2020-02-24T19:01:45Z")

</div>

let y =msg.payload.Timeseries;  
let x = y / 1000;  
let w = secondsToHms(x);

msg.payload = w;

node.status({fill:"blue",shape:"dot",text:msg.payload});

function secondsToHms(d) {  
d = Number(d);  
var h = Math.floor(d / 3600);  
var m = Math.floor(d % 3600 / 60);  
var s = Math.floor(d % 3600 % 60);

```
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
return hDisplay + mDisplay + sDisplay; 

```

}

return msg;

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [24 February 2020 19:02 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/8 "2020-02-24T19:02:22Z")

</div>

that looks nice, but it's the DATE I am after, not the TIME 🙂

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [24 February 2020 19:02 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/9 "2020-02-24T19:02:58Z")

</div>

oops, sorry about that

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 February 2020 19:04 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/10 "2020-02-24T19:04:44Z")

</div>

Works for me

 ![Screen Shot 2020-02-24 at 2.03.56 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/c/7c4959598dd41264e47f05840430823b1d360bdd.png)

---

<div class="post-metadata">

**Author:** ![Gawan](https://avatars.discourse-cdn.com/v4/letter/g/e9c0ed/32.png) [@Gawan](https://discourse.nodered.org/u/Gawan)\
**Post date:** [24 February 2020 19:06 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/11 "2020-02-24T19:06:45Z")

</div>

unfortunately I cannot use this on my function output, because I get 200 values from an SQL database query and I get a timestamp and a value  
when I use the Date/Time Formatter the value is gone afterwards  
so I have to solve this with another function node

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [24 February 2020 19:15 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/12 "2020-02-24T19:15:54Z")

</div>

var myDate = msg.payload.Timeseries;;  
var d = myDate.toGMTString();  
node.status({fill:"green",shape:"ring",text:d});

return msg;

this get you a date in day date month year and then time, you can either research a little more the GMTString opitions or parse out the stuff you don't want

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [24 February 2020 19:21 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/13 "2020-02-24T19:21:53Z")

</div>

just a note: apparently the GMTString is deprecated use the toUTCSting instead of that.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 February 2020 19:37 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/14 "2020-02-24T19:37:00Z")

</div>

F.Y.I. If you point the input and outvalues at the variables in msg.payload it won't get wiped out.

 ![Screen Shot 2020-02-24 at 2.36.18 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f5bfcaa6676eeb8913084ec2bcd3bc5d986a5b9.png)

---

<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 March 2020 19:37 UTC](https://discourse.nodered.org/t/get-nice-date-format-from-timeseries/22208/15 "2020-03-25T19:37:06Z")

</div>

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