How to Insert TimeStamps Into SQL

good day to all of you i am new to node red, i need to create a table into a database that comes from an industrial laundry at a hospital, i need to create cycle start time and cycle finish time, i get errors about parse and format, i request your help about how to convert in a propper maner time

[
    {
        "id": "f72663007f24db2a",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "38b9dfb8b8e6c204",
        "type": "mysql",
        "z": "f72663007f24db2a",
        "mydb": "3e10e97bf1ddab3a",
        "name": "hospitalv1",
        "x": 540,
        "y": 120,
        "wires": [
            [
                "652cf94177aca208"
            ]
        ]
    },
    {
        "id": "34818c4488d30185",
        "type": "ui_button",
        "z": "f72663007f24db2a",
        "name": "",
        "group": "ea5811b1fe9d49fa",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Refresh Data",
        "tooltip": "Load Data from Database",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "fa-refesh",
        "payload": "",
        "payloadType": "str",
        "topic": "topic",
        "topicType": "msg",
        "x": 130,
        "y": 120,
        "wires": [
            [
                "d525e13d1410afea"
            ]
        ]
    },
    {
        "id": "d525e13d1410afea",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "get user values",
        "func": "msg.topic = \"SELECT * FROM lavadoras_v0;\";\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 120,
        "wires": [
            [
                "38b9dfb8b8e6c204"
            ]
        ]
    },
    {
        "id": "652cf94177aca208",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 1",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 720,
        "y": 120,
        "wires": []
    },
    {
        "id": "ec868fdb9498dcd3",
        "type": "ui_chart",
        "z": "f72663007f24db2a",
        "name": "",
        "group": "ea5811b1fe9d49fa",
        "order": 2,
        "width": 0,
        "height": 0,
        "label": "values",
        "chartType": "line",
        "legend": "true",
        "xformat": "HH:mm",
        "interpolate": "linear",
        "nodata": "No Data Available",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 710,
        "y": 40,
        "wires": [
            []
        ]
    },
    {
        "id": "8727aba6947276e7",
        "type": "ui_button",
        "z": "f72663007f24db2a",
        "name": "",
        "group": "ea5811b1fe9d49fa",
        "order": 4,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Delete Chart Data",
        "tooltip": "Deletes DAta in chart",
        "color": "",
        "bgcolor": "red",
        "className": "",
        "icon": "fa-trash",
        "payload": "[]",
        "payloadType": "json",
        "topic": "topic",
        "topicType": "msg",
        "x": 490,
        "y": 40,
        "wires": [
            [
                "ec868fdb9498dcd3"
            ]
        ]
    },
    {
        "id": "bad182c93fa2585e",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Num_Lavadora",
        "diff": true,
        "name": "Num_lavadora",
        "x": 140,
        "y": 420,
        "wires": [
            [
                "0217049624e51832"
            ]
        ]
    },
    {
        "id": "0217049624e51832",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flowset_Num_Equipo",
        "func": "var Num_Equipo_var;\nflow.set(\"Num_Equipo_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 420,
        "wires": [
            [
                "c8f98b5479c3b1d3"
            ]
        ]
    },
    {
        "id": "c8f98b5479c3b1d3",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 2",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 420,
        "wires": []
    },
    {
        "id": "4d8eb2b6a7b68efb",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Terminado_Completo",
        "diff": true,
        "name": "Terminado_Completo",
        "x": 160,
        "y": 500,
        "wires": [
            [
                "d3f6899ea944c2bd"
            ]
        ]
    },
    {
        "id": "4c504cb7b08f0b93",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 3",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 500,
        "wires": []
    },
    {
        "id": "1d74940dcc2064a8",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Tipo_Ciclo",
        "diff": true,
        "name": "Tipo_Ciclo",
        "x": 120,
        "y": 560,
        "wires": [
            [
                "1f551a99addbf509"
            ]
        ]
    },
    {
        "id": "93ba046bfe8e19e7",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 4",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 560,
        "wires": []
    },
    {
        "id": "feefa4b5231951ac",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Personalizado",
        "diff": true,
        "name": "Personalizado_Ciclo",
        "x": 150,
        "y": 620,
        "wires": [
            [
                "12dea99303d3a02d"
            ]
        ]
    },
    {
        "id": "40f3d356e7c75d81",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 5",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 620,
        "wires": []
    },
    {
        "id": "a228884814c3ba9b",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Remojo",
        "diff": true,
        "name": "remojo",
        "x": 110,
        "y": 700,
        "wires": [
            [
                "e15f0ef188fded1a"
            ]
        ]
    },
    {
        "id": "1c46cb177dd5f2cb",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 6",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 700,
        "wires": []
    },
    {
        "id": "33d79ea72418963f",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Usuario",
        "diff": true,
        "name": "usuario",
        "x": 110,
        "y": 780,
        "wires": [
            [
                "f33b5e4172140141"
            ]
        ]
    },
    {
        "id": "b0be9a4272c92098",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 7",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 780,
        "wires": []
    },
    {
        "id": "7d5d85e637ecd5e0",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Num_Ticket",
        "diff": true,
        "name": "Num_Ticket",
        "x": 130,
        "y": 840,
        "wires": [
            [
                "de99d7be96677caf"
            ]
        ]
    },
    {
        "id": "751f5c90e6d45958",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 8",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 840,
        "wires": []
    },
    {
        "id": "d50ba58e6fee7c39",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Hora_inicio",
        "diff": true,
        "name": "Hora_Inicio",
        "x": 130,
        "y": 920,
        "wires": [
            [
                "0155b791cf06515c"
            ]
        ]
    },
    {
        "id": "0155b791cf06515c",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "start_time",
        "func": "var start_time_var;\nflow.set(\"start_time_var\", msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 920,
        "wires": [
            [
                "f6d2e6dab64ca9e2"
            ]
        ]
    },
    {
        "id": "f6d2e6dab64ca9e2",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 9",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 920,
        "wires": []
    },
    {
        "id": "f95010dee9efc7c4",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Hora_Fin",
        "diff": true,
        "name": "Hora_Inicio",
        "x": 130,
        "y": 1000,
        "wires": [
            [
                "f69c1d4cc97d7f07"
            ]
        ]
    },
    {
        "id": "f69c1d4cc97d7f07",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "end_time",
        "func": "var end_time_var;\nflow.set(\"end_time_var\", msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 1000,
        "wires": [
            [
                "c7632774382a416d"
            ]
        ]
    },
    {
        "id": "c7632774382a416d",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 10",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 1000,
        "wires": []
    },
    {
        "id": "1f551a99addbf509",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flow_set_tipo_ciclo",
        "func": "var tipo_ciclo_var;\nflow.set(\"tipo_ciclo_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 560,
        "wires": [
            [
                "93ba046bfe8e19e7"
            ]
        ]
    },
    {
        "id": "12dea99303d3a02d",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flow_set_personalizado",
        "func": "var personalizado_var;\nflow.set(\"personalizado_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 430,
        "y": 620,
        "wires": [
            [
                "40f3d356e7c75d81"
            ]
        ]
    },
    {
        "id": "d3f6899ea944c2bd",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "insertar_datos",
        "func": "var mensaje;\nmensaje = \"INSERT INTO lavadoras_v0 (Num_lavadora, tipo_ciclo, ciclo_personalizado, remojo, operador, num_ticket, hora_inicio, hora_fin, disponible) \";\nmensaje = mensaje + \"VALUES (\";\nmensaje = mensaje + \"\"+flow.get(\"Num_Equipo_var\")+\",\"+flow.get(\"tipo_ciclo_var\")+\"\";\nmensaje = mensaje + \",\"+flow.get(\"personalizado_var\")+\",\" + flow.get(\"remojo_var\")+\"\";\nmensaje = mensaje + \",\"+flow.get(\"usuario_var\")+\",\"+flow.get(\"ticket_var\")+\"\";\nmensaje = mensaje + \",\"+flow.get(\"start_time_var\")+\",\"+flow.get(\"end_time_var\")+\"\";\nmensaje=  mensaje + \",\"+flow.get(\"disponible_var\")+\"\";\nmensaje = mensaje + \")\";\nmsg.topic = mensaje;\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 540,
        "y": 280,
        "wires": [
            [
                "41d3f79cd098efb3",
                "38b9dfb8b8e6c204"
            ]
        ]
    },
    {
        "id": "41d3f79cd098efb3",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 11",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 280,
        "wires": []
    },
    {
        "id": "e15f0ef188fded1a",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flow_set_remojo",
        "func": "var remojo_var;\nflow.set(\"remojo_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 700,
        "wires": [
            [
                "1c46cb177dd5f2cb"
            ]
        ]
    },
    {
        "id": "f33b5e4172140141",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flow_set_usuario",
        "func": "var usuario_var;\nflow.set(\"usuario_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 780,
        "wires": [
            [
                "b0be9a4272c92098"
            ]
        ]
    },
    {
        "id": "de99d7be96677caf",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flow_set_num_ticket",
        "func": "var ticket_var;\nflow.set(\"ticket_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 840,
        "wires": [
            [
                "751f5c90e6d45958"
            ]
        ]
    },
    {
        "id": "a899fde0495c3287",
        "type": "s7 in",
        "z": "f72663007f24db2a",
        "endpoint": "0f6966b00b831166",
        "mode": "single",
        "variable": "Disonible",
        "diff": true,
        "name": "disponible",
        "x": 120,
        "y": 1080,
        "wires": [
            [
                "42025056566c8238"
            ]
        ]
    },
    {
        "id": "a6f9ad551e15cd75",
        "type": "debug",
        "z": "f72663007f24db2a",
        "name": "debug 12",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 1080,
        "wires": []
    },
    {
        "id": "42025056566c8238",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flow_set_disponible",
        "func": "var disponible_var;\nflow.set(\"disponible_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 1080,
        "wires": [
            [
                "a6f9ad551e15cd75"
            ]
        ]
    },
    {
        "id": "0e6dff5df00be7dc",
        "type": "function",
        "z": "f72663007f24db2a",
        "name": "flowset_Num_Equipo",
        "func": "var ciclo_term_var\nflow.set(\"ciclo_term_var\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 500,
        "wires": [
            [
                "4c504cb7b08f0b93"
            ]
        ]
    },
    {
        "id": "98a53bb80c42c943",
        "type": "inject",
        "z": "f72663007f24db2a",
        "name": "INSERT Into lavadoras_v0",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "INSERT INTO lavadoras_v0 ( Num_lavadora, tipo_ciclo, ciclo_personalizado, remojo, operador, num_ticket, hora_inicio, hora_fin, disponible)  VALUES ( '1', tipo_ciclo, 'Enjuague', 'Sin Remojo', 'CCG', '74403', NOW(), '2025-06-15 18:44:13', 'Falso');",
        "x": 150,
        "y": 220,
        "wires": [
            [
                "38b9dfb8b8e6c204"
            ]
        ]
    },
    {
        "id": "c2cfdddbf204e5c9",
        "type": "ui_spacer",
        "z": "f72663007f24db2a",
        "name": "spacer",
        "group": "ea5811b1fe9d49fa",
        "order": 1,
        "width": 12,
        "height": 1
    },
    {
        "id": "3e10e97bf1ddab3a",
        "type": "MySQLdatabase",
        "name": "",
        "host": "192.168.1.209",
        "port": "3306",
        "db": "hospitalv1",
        "tz": "",
        "charset": "UTF8"
    },
    {
        "id": "ea5811b1fe9d49fa",
        "type": "ui_group",
        "name": "User Values",
        "tab": "80597a7c0d642169",
        "order": 1,
        "disp": true,
        "width": 12,
        "collapse": false,
        "className": ""
    },
    {
        "id": "0f6966b00b831166",
        "type": "s7 endpoint",
        "transport": "iso-on-tcp",
        "address": "192.168.1.2",
        "port": "102",
        "rack": "0",
        "slot": "1",
        "localtsaphi": "01",
        "localtsaplo": "00",
        "remotetsaphi": "01",
        "remotetsaplo": "00",
        "connmode": "rack-slot",
        "adapter": "",
        "busaddr": 2,
        "cycletime": 1000,
        "timeout": 2000,
        "name": "Hospital1",
        "vartable": [
            {
                "addr": "DB17,I0",
                "name": "Num_Lavadora"
            },
            {
                "addr": "DB17,X2.0",
                "name": "Terminado_Completo"
            },
            {
                "addr": "DB17,S4.15",
                "name": "Tipo_Ciclo"
            },
            {
                "addr": "DB17,S260.15",
                "name": "Personalizado"
            },
            {
                "addr": "DB17,S516.15",
                "name": "Remojo"
            },
            {
                "addr": "DB17,S772.15",
                "name": "Usuario"
            },
            {
                "addr": "DB17,DI1028",
                "name": "Num_Ticket"
            },
            {
                "addr": "DB17,DTL1032",
                "name": "Hora_inicio"
            },
            {
                "addr": "DB17,DTL1044",
                "name": "Hora_Fin"
            },
            {
                "addr": "DB17,S1056.15",
                "name": "Disonible"
            }
        ]
    },
    {
        "id": "80597a7c0d642169",
        "type": "ui_tab",
        "name": "DB",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Please confirm:

  1. Is this a MySQL or MariaDB database?
  2. What is the structure of the table lavadoras_v0? (If you have access to the SQL command line, you can obtain this with describe lavadoras_v0;) If you have phpMyAdmin I am sure you can find the structure there too.
  3. What does the data look like as it comes into Node-red? Examples of each message type please.
  4. What are these errors about parse and format? Examples of each error please.

Your use of flow context variables to store each value is poor Node-red form. I am not familiar with S7 messages but I suspect you should be using a join node to gather all these values into a single message.

Your SQL statement is very bad SQL form. You should be using a prepared query.

MariaDB database


the data


    -> ;
+---------------------+-------------+------+-----+---------+----------------+
| Field               | Type        | Null | Key | Default | Extra          |
+---------------------+-------------+------+-----+---------+----------------+
| Transaccion         | int(11)     | NO   | PRI | NULL    | auto_increment |
| Num_lavadora        | int(11)     | NO   |     | NULL    |                |
| tipo_ciclo          | varchar(15) | NO   |     | NULL    |                |
| ciclo_personalizado | varchar(15) | NO   |     | NULL    |                |
| remojo              | varchar(15) | NO   |     | NULL    |                |
| operador            | varchar(15) | NO   |     | NULL    |                |
| num_ticket          | int(11)     | NO   |     | NULL    |                |
| hora_inicio         | datetime    | NO   |     | NULL    |                |
| hora_fin            | datetime    | NO   |     | NULL    |                |
| disponible          | varchar(15) | NO   |     | NULL    |                |
+---------------------+-------------+------+-----+---------+----------------+

thanks in advance for your repply, i am new to all of these communication into sql, thank you


Here is an example of formatting a datetime field for an INSERT statement in MySQL

Note that for me in UK and with my database locale set to UTC, this value "2025-06-16 23:12:28" is accepted in an INSERT query.
You may need a different format depending on your locale and the locale of your database.
Make sure you verify that the timestamps stored in the database are what you would expect to see.

Here is an example of constructing a prepared INSERT statement, which is much safer than your code

It's up to you how you construct msg.payload but flow context is not desirable and should not be needed. I suggest you read up on the join node manual mode.

Also your database will have a field type that allows you to specify that the default value is the current time. Then when you add a record it will automatically add the correct timestamp.