# From data picker node to UTC

**URL:** https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026
**Category:** General
**Created:** [30 January 2020 03:50 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026 "2020-01-30T03:50:47Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![NODE777](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@NODE777](https://discourse.nodered.org/u/NODE777)
#### Post date: [30 January 2020 03:50 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/1 "2020-01-30T03:50:48Z")

</div>

Hi

I would need to convert to **ms** UTC from the selected data with the date selector node in order to make a sqlite query using the SELECT clause to my db.  
The db only includes the UTC time.  
I'm using the data picker node hooked up to moment node and storing that date on global variable so I'm going to be able to retrieve that value to do a db query.  
The goal is to select a time range from the db for display on a chart or table.  
I don't have enough background on JS Date object, I google this subject but I could get an answer. .  
Any help with that?

Thanks

---

<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: [30 January 2020 10:03 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/2 "2020-01-30T10:03:48Z")

</div>

Did you look at the options for the Moment node's Output?  
 ![Screen Shot 2020-01-30 at 5.02.28 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8a69dd8b82b41fc5f295501925ab49327212e6fd.png)  
You might want to look at that link...

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [30 January 2020 22:05 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/3 "2020-01-30T22:05:29Z")

</div>

> [@NODE777](#):
>
> The db only includes the UTC time.

And that's how it should be 😀

Always store as UTC and convert for display.

Just be aware, that most systems use SECONDS not MILLISECONDS as JavaScript does.

So if you are getting a JavaScript value such as from `Date.now()`, that is in ms but if you are getting a date as a number from other systems, you will likely need to multiply by 1000 to use with JavaScript..

---

<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: [30 January 2020 22:13 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/4 "2020-01-30T22:13:22Z")

</div>

If you have a js Date object you should just be able to convert that to a string using toString(). The database server should understand that.

---

<div class="post-metadata">

### Author: ![NODE777](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@NODE777](https://discourse.nodered.org/u/NODE777)
#### Post date: [31 January 2020 05:03 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/5 "2020-01-31T05:03:14Z")

</div>

@zenofmud @TotallyInformation@Colin  
Thank you guys for the tips I'm working on that ! ,

---

<div class="post-metadata">

### Author: ![NODE777](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@NODE777](https://discourse.nodered.org/u/NODE777)
#### Post date: [4 February 2020 04:37 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/6 "2020-02-04T04:37:00Z")

</div>

Hi again

I'm facing an issue that maybe can be silly but it prevent me from move forward with the topic I asked help for on 1/30/20.

My db hvac1 has a column named as UTC NUMERIC.  
I'm using a couple of data picker to select data between two days range.  
Those data picker are hooked up to 2 Moment nodes.  
The moment nodes are set up so the output message are **global.stday**  
and **global.enday.**

Those variables, **stday** and **enday** contain the corresponding **utc** timestamp as numeric value.

I'm trying to implement a **SELECT \* FROM hvac1 WHERE UTC BETWEEN stday AND enday** using a function node.  
Above I tried writing as 'stday' and stday, the same for enday but it doesn't work.

I wrote this code inside the function node and connected to sqlite node and **it does work** using numeric timestamp s as you can see below.

```auto
var stday='1580748250808';
var enday='1580753650821';
var b= "SELECT * FROM hvac1 WHERE UTC BETWEEN '1580748250808' AND '1580753650821' " ;
msg.topic=b;

return msg;

```

The point is that I would need your help to write :  
**"SELECT \* FROM hvac1 WHERE UTC BETWEEN '1580748250808' AND '1580753650821'" ;**  
**but using** the variables stday and enday once they has been retrieved from global storage,

Thank you very much for some help.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [4 February 2020 06:52 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/7 "2020-02-04T06:52:21Z")

</div>

To help, we need to know the database type and the node you are using to write to it.

---

<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: [4 February 2020 07:11 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/8 "2020-02-04T07:11:05Z")

</div>

Also add a debug node showing the query you are sending to the dB so you can check it is correct. Plus you say it doesn't work but have not explained what you mean by that, is it wrong data returned or error message or what?

---

<div class="post-metadata">

### Author: ![fieldgoal](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fieldgoal/32/16739_2.png) [@fieldgoal](https://discourse.nodered.org/u/fieldgoal)
#### Post date: [4 February 2020 07:36 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/9 "2020-02-04T07:36:02Z")

</div>

hey node777,

you just need to put the right string escape sequences in your querry:

```auto
var stday='1580748250808';
var enday='1580753650821';
var b= "SELECT * FROM hvac1 WHERE UTC BETWEEN ' " + stday + " ' AND ' "+ enday +" ' " ;
msg.topic=b;

return msg;

```

i'm not sure why you put your unix timestamp in ' ' these single quotes tho.

And to check if your string is correctly formatted you can use a debug node, as colin suggested.

---

<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: [4 February 2020 09:08 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/10 "2020-02-04T09:08:58Z")

</div>

@fieldgoal is right, you should not have quotes round the times, they are numbers not strings or field names. I guess that it does work with the quotes as the db is converting to numbers for you, but that is a waste of time and electricity.

---

<div class="post-metadata">

### Author: ![NODE777](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@NODE777](https://discourse.nodered.org/u/NODE777)
#### Post date: [6 February 2020 04:50 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/11 "2020-02-06T04:50:42Z")

</div>

@Colin  
@TotallyInformation  
@fieldgoal

Hi there !!!!  
Thank so much for your help.

**Here it is what is working**  
It was about using the right string escape as **fieldgoal** suggested me, plus all your questions that helped me to get a workaround on this

 ![Fuction node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/630b54652259cae2746270722b90ede08784c942.png)

I was taken this SELECT clause for implement this function:

_SELECT \* FROM hvac WHERE UTC BETWEEN 'stday' AND 'enday'_  
I took this from some sqlite tutorial.

These are the nodes that work to select from **stday** at Local time and **enday**  
at local time.

 ![Flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/430831bdd4f9d0e9bac41b025f1cfa311e94897b.png)

![Moment stday](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac9088ac3b8a2f5328aaec13bd266b57fbddf5d8.png)

![Moment enday](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/afc800cfd3595fc093bde2bd1897b5e7ba52f429.png)

Thanks so much to all of you.

---

<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: [20 February 2020 04:50 UTC](https://discourse.nodered.org/t/from-data-picker-node-to-utc/21026/12 "2020-02-20T04:50:45Z")

</div>

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