Form node: mistake on output of two date fields

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

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)?

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"

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

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

Answer this☝️ please?

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

here are the screenshots :smiley:

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:

Not working

I need to specified also start and stop hours

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

No, that is not valid syntax

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.

Hi,

i've solved my problem using a very complex solution (may be) :thinking: :scream:

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