# Form node: mistake on output of two date fields

**URL:** <https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754>\
**Category:** Dashboard\
**Tags:** node-red-contrib-mssql-plus\
**Created:** [25 April 2025 13:29 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754 "2025-04-25T13:29:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [25 April 2025 13:29 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/1 "2025-04-25T13:29:45Z")

</div>

Hi to everybody.

i've insert a form node with 2 date fileds ("start" and "end" fileds). Then insert 2 date:

- start = 24/04/2025
- end = 25/04/2025  
The debug node, showing 1 day less

Any idea? Thanks a lot

 ![form_node_error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/a/1a519dc202064f9b549f04de85272024a08b2f86.png)

---

<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:** [25 April 2025 13:56 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/2 "2025-04-25T13:56:50Z")

</div>

The time is correct - it is exactly midnight of your chosen date, only the representation is in ISO format (aka zulu / UTC).

Let me guess, you are in an area where the time is UTC+2?

How you deal with this depends you are doing with the date.

If you need a string with ONLY the date portion, then you can do that using a change node and $moment to convert the datetime into a simple date string.

* * *

EDIT

I just spotted a partial SQL string in your screenshot. Are you querying a database for start/end time? What format are those fields in your database (and what kind of database is this / what database nodes are you using)?

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [25 April 2025 15:35 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/3 "2025-04-25T15:35:10Z")

</div>

> [@Steve-Mcl](#):
>
> I just spotted a partial SQL string in your screenshot. Are you querying a database for start/end time? What format are those fields in your database (and what kind of database is this / what database nodes are you using)?

Hi Steve,

thanks for your reply. I need that the user enter two dates using UI; then I use them to execute a query on SQL DB like "SELECT \* FROM MyTable WHERE MyDate BETWEEN start AND end OREDER BY MyDate DESC". To connect to the Server SQL i use the node "node-red-contrib-mssql-plus"

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [25 April 2025 15:36 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/4 "2025-04-25T15:36:09Z")

</div>

> [@Steve-Mcl](#):
>
> Let me guess, you are in an area where the time is UTC+2?

Yes is correct; is possible to change the Node-Red time zone?

---

<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:** [25 April 2025 15:37 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/5 "2025-04-25T15:37:04Z")

</div>

> [@jumpier](#):
>
> is possible to change the Node-Red time zone?

Yes, but that is not the correct way to deal with dates.

> [@Steve-Mcl](#):
>
> What format are those fields in your database

Answer this☝️ please?

Also, show me a screenshot of the SQL-PLUS node (are you using parameters?)

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [25 April 2025 16:29 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/6 "2025-04-25T16:29:14Z")

</div>

here are the screenshots 😃

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/28924cec6cdc6ff83e1051a197dacbda089e0613.png)

 ![MSSQL](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/86d3e7e45458948b0e7bb97ea70379a3de8ff882.png)

 ![function](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/b/dbf46632263d4eb3c1ca1cd92f56cbe56d3f2a84.png)

 ![create_table](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02453bc735ed9126ef37b94dc1b223a58df78e00.png)

---

<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:** [25 April 2025 16:40 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/7 "2025-04-25T16:40:25Z")

</div>

ok, it is not best practice to feed values directly from user input to your database (you risk SQL Inject hacks) - It is ~~better~~ safer (and actually easier) to use parameters.

Get rid of the function node (which btw is why you are getting bad dates!) and try this instead:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f591b8ce8aab78612426eb5867857ec59bc9e45f.png)

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [25 April 2025 17:57 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/8 "2025-04-25T17:57:23Z")

</div>

> [@Steve-Mcl](#):
>
> ok, it is not best practice to feed values directly from user input to your database (you risk SQL Inject hacks) - It is better (and actually easier) to use parameters.
> 
> Get rid of the function node (which btw is why you are getting bad dates!) and try this instead:

Not working

I need to specified also start and stop hours

For istance  
@dateStart + " 00:00:00.000' AND '" + @dateEnd + " 23:59:59.999'

---

<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:** [25 April 2025 18:22 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/9 "2025-04-25T18:22:02Z")

</div>

> [@jumpier](#):
>
> For istance  
> @dateStart + " 00:00:00.000' AND '" + @dateEnd + " 23:59:59.999'

No, that is not valid syntax

> [@jumpier](#):
>
> I need to specified also start and stop hours

You already have a full time stamp (in iso format - tour screenshot shows that).

  

If you export the DDL of your table and a demo flow, I will take a look tomorrow.

In the mean time, try using the SQL Type `DateTime`, try parsing the start and enddate values to proper `Date` objects.

---

<div class="post-metadata">

**Author:** ![jumpier](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jumpier/32/44058_2.png) [@jumpier](https://discourse.nodered.org/u/jumpier)\
**Post date:** [26 April 2025 09:39 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/10 "2025-04-26T09:39:42Z")

</div>

Hi,

i've solved my problem using a very complex solution (may be) 🤔😱

```auto
var start = new Date(msg.payload['start']).toLocaleString(); // return date DD/MM/YYYY
var end = new Date(msg.payload['end']).toLocaleString();
start = start.slice(0,10);
start = start.split("/").reverse().join("/"); // return date YYYY/MM/DD
start = start.replace("/", "-").replace("/", "-"); // return date YYYY-MM-DD
end = end.slice(0,10);
end = end.split("/").reverse().join("/");
end = end.replace("/", "-").replace("/", "-");

```

Then i've used the variables "start" and "end" into my query

Now another "date" problem: on the "table node" the date is showing with 2 hour less

 ![sql_vs_nodered_grid](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/46898dbe1adc383dcabc88b24c1414ac2c6e9069.png)

 ![table_node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27fb2f23703b76740ea1326bac5da851649ed278.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:** [26 May 2025 09:40 UTC](https://discourse.nodered.org/t/form-node-mistake-on-output-of-two-date-fields/96754/11 "2025-05-26T09:40:07Z")

</div>

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