# Date Picker -Dashboard question

**URL:** <https://discourse.nodered.org/t/date-picker-dashboard-question/17074>\
**Category:** Dashboard\
**Created:** [24 October 2019 08:36 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074 "2019-10-24T08:36:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![biz](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@biz](https://discourse.nodered.org/u/biz)\
**Post date:** [24 October 2019 08:36 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074/1 "2019-10-24T08:36:38Z")

</div>

I am using the date picker on a web form. I then proceed to store it into a database.  
The problem I have it sends the date in msg.payload as "1571826972734" I would like this to be human readable. Looking at the github documentation doesn't show anyway to configure that except to change the format of it. as in mm-dd-yyyy or yyyy-mm-dd etc but it still sends the 1571826972734 as a value.

I can see if I use a debug node and click on the output it is able to translate it into a date.  
2 questions come from this.

1. can I change the date that it sends via msg.payload?
2. If I cant do 1 then what is the formula it is using that I can convert it back from 1571826972734 to human readable via a function node?

---

<div class="post-metadata">

**Author:** ![3amWednesday](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/3amwednesday/32/10371_2.png) [@3amWednesday](https://discourse.nodered.org/u/3amWednesday)\
**Post date:** [24 October 2019 10:06 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074/2 "2019-10-24T10:06:03Z")

</div>

You can use a function node to change it back to human time.

```auto
var d = new Date(msg.payload);
var str = d.toDateString; //Wed Oct 23 2019
msg.payload = str;

```

Check out Javascript Date Functions for more formats.

Hope this helps

---

<div class="post-metadata">

**Author:** ![biz](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@biz](https://discourse.nodered.org/u/biz)\
**Post date:** [24 October 2019 10:30 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074/3 "2019-10-24T10:30:43Z")

</div>

ohh man. I was so close. I thought originally it was unix time but converting it gave horribly wrong times!  
Thanks this does help 🙂 Appreciate it  
After much dinking around with your suggestion I have got it to work with this  
var d = new Date(msg.payload);  
var day = d.getDate();  
var month = d.getMonth();  
var monthformat = month + 1;  
var year = d.getFullYear();  
msg.payload = day +"-"+ monthformat +"-"+ year;

---

<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:** [24 October 2019 11:22 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074/4 "2019-10-24T11:22:36Z")

</div>

in general you should do the conversion when reading back out of a database rather than before going in - so when the clock changes for summer/winter time you won't get duplicate entries or a gap.

---

<div class="post-metadata">

**Author:** ![biz](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@biz](https://discourse.nodered.org/u/biz)\
**Post date:** [24 October 2019 11:26 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074/5 "2019-10-24T11:26:01Z")

</div>

That is a good idea. right now they are being stored as the date picker submits them. I am using an html template node to put them into a table. I would like to format the ones with the dates to that 🙂

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [24 October 2019 18:02 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074/6 "2019-10-24T18:02:37Z")

</div>

I agree with Dave -- _please_ do not store any timestamps in human-readable strings! You will end up with a database that cannot be searched by date/time ranges, and will be near impossible to present correctly to users in different timezones...

The only exception is to use the ISO-8601 date formatting -- which is simple to do in JS:

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

```

When you pull apart the internal Date object into its "day" value, for instance, you can get the \*local" day of the month, not the actual GMT date (depending upon your timezone offset and how close to midnight it is). Same thing with transitions between months, years, and daylight savings time!

Bottom Line: Always store the internal date in its native format, and format it for output display only... your life will be simpler, and your applications more predictable and easy to maintain.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [24 October 2019 18:16 UTC](https://discourse.nodered.org/t/date-picker-dashboard-question/17074/7 "2019-10-24T18:16:09Z")

</div>

Oh, and _if you really don't need the time component at all_, it's best to use the format `yyyy-MM-dd` -- not only does it sort chronologically, but JS can interpret it back into a Date object easily:

```auto
// convert a GMT date string into a Date in my local timezone
> new Date("2019-05-04").toDateString()
'Fri May 03 2019' <--- since I am behind the International Date line

// convert a local date string into a local Date object in my tz
> new Date("2019-05-04".split("-")).toDateString()
'Sat May 04 2019'

```

Using the `m/d/yyyy` format is ambiguous -- `4/5/2019` would be "April 5, 2019" in the U.S. but it could be interpretted as "May 4, 2019" in Europe...
