# Get time matching ui\_date\_picker

**URL:** <https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601>\
**Category:** General\
**Created:** [14 March 2021 00:48 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601 "2021-03-14T00:48:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rufus](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@Rufus](https://discourse.nodered.org/u/Rufus)\
**Post date:** [14 March 2021 00:48 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/1 "2021-03-14T00:48:07Z")

</div>

Hi  
I am trying to store some data alongside the date without the hours (in milliseconds).  
I want just the date (without the hour) to match the value given by the ui\_date\_picker.  
I am a beginner, it can be just simple javascript but I`ve trying but didn´t achieve nothing.  
I want values like this given by the date picker.  
 ![Screenshot_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f30e1e15a1e8d636e8387837dc73175b1cb0853e.png)  
I´ll be glad if someone can help me.

---

<div class="post-metadata">

**Author:** ![burtonboucher](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/burtonboucher/32/7806_2.png) [@burtonboucher](https://discourse.nodered.org/u/burtonboucher)\
**Post date:** [14 March 2021 01:36 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/2 "2021-03-14T01:36:50Z")

</div>

> [@Rufus](#):
>
> ui\_date\_picker

> [@Date Picker -Dashboard question](https://discourse.nodered.org/t/date-picker-dashboard-question/17074):
>
> 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…

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [14 March 2021 02:51 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/3 "2021-03-14T02:51:49Z")

</div>

I use [node-red-contrib-moment](https://flows.nodered.org/node/node-red-contrib-moment)

here is an example....

 ![Screenshot from 2021-03-13 21-50-27](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/805183d97b800ed6a3afbe26793bee1d17e15927.png)

```auto
[{"id":"38408627.2b4cda","type":"moment","z":"150b582b.3e6d68","name":"year","topic":"","input":"epoch","inputType":"msg","inTz":"America/New_York","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY","locale":"C","output":"year","outputType":"msg","outTz":"America/New_York","x":330,"y":860,"wires":[["16c64f42.d8cb39"]]},{"id":"16c64f42.d8cb39","type":"moment","z":"150b582b.3e6d68","name":"month","topic":"","input":"epoch","inputType":"msg","inTz":"America/New_York","adjAmount":0,"adjType":"days","adjDir":"add","format":"MM","locale":"C","output":"month","outputType":"msg","outTz":"America/New_York","x":450,"y":860,"wires":[["239baeb.17c58d2"]]},{"id":"239baeb.17c58d2","type":"moment","z":"150b582b.3e6d68","name":"day","topic":"","input":"epoch","inputType":"msg","inTz":"America/New_York","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD","locale":"C","output":"day","outputType":"msg","outTz":"America/New_York","x":570,"y":860,"wires":[["4cc6e2d8.4df52c"]]},{"id":"4cc6e2d8.4df52c","type":"moment","z":"150b582b.3e6d68","name":"hour","topic":"","input":"epoch","inputType":"msg","inTz":"America/New_York","adjAmount":0,"adjType":"days","adjDir":"add","format":"HH","locale":"C","output":"hour","outputType":"msg","outTz":"America/New_York","x":690,"y":860,"wires":[["c059c10b.4cf98"]]},{"id":"c059c10b.4cf98","type":"moment","z":"150b582b.3e6d68","name":"minutes","topic":"","input":"epoch","inputType":"msg","inTz":"America/New_York","adjAmount":0,"adjType":"days","adjDir":"add","format":"mm","locale":"C","output":"minutes","outputType":"msg","outTz":"America/New_York","x":820,"y":860,"wires":[["97523b5.7c753c8"]]},{"id":"97523b5.7c753c8","type":"moment","z":"150b582b.3e6d68","name":"seconds","topic":"","input":"epoch","inputType":"msg","inTz":"America/New_York","adjAmount":0,"adjType":"days","adjDir":"add","format":"ss","locale":"C","output":"seconds","outputType":"msg","outTz":"America/New_York","x":960,"y":860,"wires":[["67b8044e.6bb984"]]},{"id":"766a6b3a.2e952c","type":"inject","z":"150b582b.3e6d68","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":860,"wires":[["38408627.2b4cda"]]},{"id":"67b8044e.6bb984","type":"debug","z":"150b582b.3e6d68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1090,"y":860,"wires":[]}]

```

see this for formatting it to your needs  
[https://momentjs.com/docs/#/displaying/format/](https://momentjs.com/docs/#/displaying/format/)

---

<div class="post-metadata">

**Author:** ![Rufus](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@Rufus](https://discourse.nodered.org/u/Rufus)\
**Post date:** [14 March 2021 17:41 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/4 "2021-03-14T17:41:14Z")

</div>

I just want de value in milliseconds of the date at midnight as the given by the date picker to match it later with a database.

Can someon help me?

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [14 March 2021 17:51 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/5 "2021-03-14T17:51:44Z")

</div>

@Rufus - wrote: " I am trying to store some data alongside the date without the hours (in milliseconds).  
I want just the date (without the hour) to match the value given by the ui\_date\_picker."

We are guessing at what you want here because your Question is hard to understand.

The value given by the ui\_date\_picker is a epoc time in numbers of ms. How can you possibly match the date (without the hour) to a epoc time ????

can you please post the time in the format you want  
IE: Jan 18th Feb 2020????

to match it???? it is what ???? take your time ..... write out what your trying to achieve.

---

<div class="post-metadata">

**Author:** ![Rufus](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@Rufus](https://discourse.nodered.org/u/Rufus)\
**Post date:** [14 March 2021 18:03 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/6 "2021-03-14T18:03:26Z")

</div>

Sorry for not being clear. What I am trying to say is that I want a function to give values as the ones given by the date picker.  
Example:  
Value given by date picker in milliseconds:  
 ![Screenshot_2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/f/3fdf17d42e9d17366a838cb272e5fe743bd0d991.png)  
The same value but in diferent formt to add context:  
 ![Screenshot_3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8e0c623389dbc9d332be15f829e75a87d4e207d5.png)

I just want the same value as the first one given by a function.

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [14 March 2021 18:19 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/7 "2021-03-14T18:19:10Z")

</div>

[node-red-contrib-moment](https://flows.nodered.org/node/node-red-contrib-moment) does what you need.

 ![Screenshot from 2021-03-14 14-15-59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85f31bb64ee10658a1ab422fd47d2fca98711ce6.jpeg)

```auto
[{"id":"6e772f0f.e01a18","type":"moment","z":"150b582b.3e6d68","name":"","topic":"","input":"payload","inputType":"msg","inTz":"America/Detroit","adjAmount":0,"adjType":"days","adjDir":"add","format":"x","locale":"en-US","output":"payload","outputType":"msg","outTz":"America/Detroit","x":780,"y":840,"wires":[["25be28b7.4de34"]]},{"id":"5504e2ae.998644","type":"change","z":"150b582b.3e6d68","name":"msg.payload = 5/3/2021 1:00:00","rules":[{"t":"set","p":"payload","pt":"msg","to":"5/3/2021 1:00:00","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":840,"wires":[["6e772f0f.e01a18"]]},{"id":"5ecb6c8d.9f51d4","type":"debug","z":"150b582b.3e6d68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1130,"y":840,"wires":[]},{"id":"e213fa95.ca5a08","type":"inject","z":"150b582b.3e6d68","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":840,"wires":[["5504e2ae.998644"]]},{"id":"25be28b7.4de34","type":"function","z":"150b582b.3e6d68","name":"","func":"//string to number\nmsg.payload = Number(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":840,"wires":[["5ecb6c8d.9f51d4"]]}]

```

You send it a date and it will send back a time in ms ... epoc  
It works both ways.  
I recommend reading the documentation on node-red-contrib-moment

---

<div class="post-metadata">

**Author:** ![Ashfaak](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ashfaak/32/34409_2.png) [@Ashfaak](https://discourse.nodered.org/u/Ashfaak)\
**Post date:** [14 March 2021 20:13 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/8 "2021-03-14T20:13:47Z")

</div>

Hi @Rufus

I believe I've run into this same issue in the past. What timezone are you accessing the dashboard from? I think you'll find if you change the timezone of the PC accessing the dashboard to GMT/UTC the date picker gives you the correct date.

My workaround was to subtract 2 hours (2x60x60x1000) from the payload (since I'm in UTC+2, and most users will be as well). If a user accesses the dashboard from a time zone UTC+(\>2) the datepicker will return the incorrect date.

Edit: I see in a pic you posted that you're in UTC+1. Try subtracting 1x60x60x1000 from the payload. I'm not sure if dst affects you. You might have to adjust accordingly.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 March 2021 20:25 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/9 "2021-03-14T20:25:35Z")

</div>

Try this...

> [@Dashboard ui\_Form Date](https://discourse.nodered.org/t/dashboard-ui-form-date/32511/18):
>
> Demo... Chosen date was 2020/09/06... [image] ... times are output in UTC, I am in UTC+1 (so add the offset and you get 00:00 of the correct date) The issue is purely visual - the date / time is in-fact correct, merely represented as UTC. If need be, you can use a function like below to get a local date/time representation... function convertUTCDateToLocalDate(date) { var newDate = new Date(date.getTime()+date.getTimezoneOffset()\*60\*1000); var offset = date.getTimezoneOffset() / 6…

Essentially, this function can deduct the time offset based on timezone to ensure correct date...

```javascript
msg.payload = convertUTCDateToLocalDate(msg.payload);

return msg;

function convertUTCDateToLocalDate(date) {
    date = new Date(date);
    var newDate = new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);
    var offset = date.getTimezoneOffset() / 60;
    var hours = date.getHours();
    newDate.setHours(hours - offset);
    return newDate;
}

```

---

<div class="post-metadata">

**Author:** ![Rufus](https://avatars.discourse-cdn.com/v4/letter/r/3ec8ea/32.png) [@Rufus](https://discourse.nodered.org/u/Rufus)\
**Post date:** [14 March 2021 22:20 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/10 "2021-03-14T22:20:08Z")

</div>

I tried a simple solution (that do the job in my project) and saved the data with a string with the date. I get the date with [node-red-contrib-moment](https://flows.nodered.org/node/node-red-contrib-moment) node as a sting and split it to get just the date.  
 ![Screenshot_5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c5a6168f328c3b37755cb62a702da1e2fd2f3b6e.png)  
I´ll try what @Steve-Mcl suggested in the future when I need it.  
Thank all for the replies.

---

<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:** [13 May 2021 22:20 UTC](https://discourse.nodered.org/t/get-time-matching-ui-date-picker/42601/11 "2021-05-13T22:20:15Z")

</div>

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