Forms widget doesn't pick the right date

Not sure why, but the date picker on the forms node in dashboard doesn't pick the date i select.
Is anyone else seeing this?
I choose today's date from the date picker and debug node says yesterdays date !

Here's what i see in debug
image

Any suggestions on a fix?
TIA

Is that debug output direct on the output of the ui_form? If so then what versions of node-red, node-red-dashboard and node.js are you using?

Here are the details

node-red version -v2.1.4
node js version - v14.19.3
npm version -v6.14.17
node-red-dashboard version -v3.1.3

I just noticed that my pi has an older node red version. 2.2.2 upgrade in progress. Shall run it again and see if this problem still exists

-- UPDATE - Still the same issue

You didn't say whether the debug output you showed is directly on the output of the form node.
Select the form node and export it (Ctrl-E) and paste it here please. Use the </> button at the top of the forum entry window when pasting it.
Also please restart node-red in a terminal and post the full terminal output here. Use the </> button for that too.
You are a bit out of date on the dashboard too, though I would not expect that to make any difference.

The date output by the form is UTC

I am in GMT+1 so when I select 29th ~ 30th I get...
image

  • I guess you are processing the values before sending them to the debug window? If so, then you are not taking the UTC offset into account - OR - the timezone on your node-red server is wrong.

Show us your flow from UI-FORM to DEBUG node (is there any FUNCTION, MOMENT or JSONata in-between them?)

[
    {
        "id": "d4fbd7b38f7a3124",
        "type": "ui_form",
        "z": "670ff5a7f28a2f47",
        "name": "",
        "label": "",
        "group": "8200bbc2589ed62e",
        "order": 6,
        "width": 8,
        "height": 1,
        "options": [
            {
                "label": "Name",
                "value": "Name",
                "type": "text",
                "required": true,
                "rows": null
            },
            {
                "label": "Date of Application",
                "value": "DateOfApplication",
                "type": "date",
                "required": true,
                "rows": null
            },
            {
                "label": "Available Holidays",
                "value": "AvailableHolidays",
                "type": "number",
                "required": false,
                "rows": null
            },
            {
                "label": "Days Requested",
                "value": "DaysRequested",
                "type": "number",
                "required": false,
                "rows": null
            },
            {
                "label": "From",
                "value": "From",
                "type": "date",
                "required": false,
                "rows": null
            },
            {
                "label": "To",
                "value": "To",
                "type": "date",
                "required": false,
                "rows": null
            },
            {
                "label": "Resuming Work On",
                "value": "ResumingWorkOn",
                "type": "date",
                "required": false,
                "rows": null
            },
            {
                "label": "Backed Up By",
                "value": "BackedUpBy",
                "type": "text",
                "required": false,
                "rows": null
            },
            {
                "label": "Handover Backup",
                "value": "HandoverBackup",
                "type": "checkbox",
                "required": false,
                "rows": null
            },
            {
                "label": "Contact Address",
                "value": "ContactAddress",
                "type": "multiline",
                "required": false,
                "rows": 2
            },
            {
                "label": "Contact Number",
                "value": "ContactNumber",
                "type": "text",
                "required": false,
                "rows": null
            }
        ],
        "formValue": {
            "Name": "",
            "DateOfApplication": "",
            "AvailableHolidays": "",
            "DaysRequested": "",
            "From": "",
            "To": "",
            "ResumingWorkOn": "",
            "BackedUpBy": "",
            "HandoverBackup": false,
            "ContactAddress": "",
            "ContactNumber": ""
        },
        "payload": "",
        "submit": "submit",
        "cancel": "cancel",
        "topic": "topic",
        "topicType": "msg",
        "splitLayout": "",
        "className": "",
        "x": 610,
        "y": 600,
        "wires": [
            [
                "1019cbe995c63db0"
            ]
        ]
    },
    {
        "id": "1019cbe995c63db0",
        "type": "debug",
        "z": "670ff5a7f28a2f47",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 600,
        "wires": []
    },
    {
        "id": "8200bbc2589ed62e",
        "type": "ui_group",
        "name": "Holiday Request",
        "tab": "0add88570f6db7ad",
        "order": 2,
        "disp": false,
        "width": "20",
        "collapse": false,
        "className": ""
    },
    {
        "id": "0add88570f6db7ad",
        "type": "ui_tab",
        "name": "Admin View",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

That's the 2 nodes i am using
Right now, it shows todays date. In the morning, it was showing me yesterday's date.
My pi is having the right date and time when i run "date" in the terminal.

When I import that flow then in the debug I see, for example,

DateOfApplication: "2022-06-27T23:00:00.000Z"

Which is consistent with Steve's post.
Is that not what you see?

Yes, that is what i see when i wire it to the debug as well.
You must have selected 28th (today) in the date picker and it shows 27th on the debug, i don't quite follow how to rectify this from the previous messages on this thread :frowning:

That isn't what you showed in your initial post (you showed only the date, not the full timestamp). The node returns the timestamp of the start of the day local time, which for me is 23:00 on 27th UTC, which is the same time as 00:00 today UTC+1. I agree that this is not what one might expect a date picker to return, but that is what it does.

You can use, for example, the moment node to get it shown in local time if that is what you want.

maybe you can use a Change node with a Jsonata expression that uses the $moment library to convert the UTC representation of the date to local. For example

"DateOfApplication": $moment(payload.DateOfApplication).format("YYYY-MM-DD"),

Test Flow

[{"id":"d4fbd7b38f7a3124","type":"ui_form","z":"54efb553244c241f","name":"","label":"","group":"8200bbc2589ed62e","order":6,"width":8,"height":1,"options":[{"label":"Name","value":"Name","type":"text","required":true,"rows":null},{"label":"Date of Application","value":"DateOfApplication","type":"date","required":true,"rows":null},{"label":"Available Holidays","value":"AvailableHolidays","type":"number","required":false,"rows":null},{"label":"Days Requested","value":"DaysRequested","type":"number","required":false,"rows":null},{"label":"From","value":"From","type":"date","required":false,"rows":null},{"label":"To","value":"To","type":"date","required":false,"rows":null},{"label":"Resuming Work On","value":"ResumingWorkOn","type":"date","required":false,"rows":null},{"label":"Backed Up By","value":"BackedUpBy","type":"text","required":false,"rows":null},{"label":"Handover Backup","value":"HandoverBackup","type":"checkbox","required":false,"rows":null},{"label":"Contact Address","value":"ContactAddress","type":"multiline","required":false,"rows":2},{"label":"Contact Number","value":"ContactNumber","type":"text","required":false,"rows":null}],"formValue":{"Name":"","DateOfApplication":"","AvailableHolidays":"","DaysRequested":"","From":"","To":"","ResumingWorkOn":"","BackedUpBy":"","HandoverBackup":false,"ContactAddress":"","ContactNumber":""},"payload":"","submit":"submit","cancel":"cancel","topic":"topic","topicType":"msg","splitLayout":"","className":"","x":350,"y":1680,"wires":[["524995b4f4eb0528","c67030e5dfe0410a"]]},{"id":"1019cbe995c63db0","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":1680,"wires":[]},{"id":"524995b4f4eb0528","type":"change","z":"54efb553244c241f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t   \"Name\": Name,\t   \"DateOfApplication\": $moment(payload.DateOfApplication).format(\"YYYY-MM-DD\"),\t   \"AvailableHolidays\": payload.AvailableHolidays,\t   \"DaysRequested\": payload.DaysRequested,\t   \"From\": $moment(payload.From).format(\"YYYY-MM-DD\"),\t   \"To\": $moment(payload.To).format(\"YYYY-MM-DD\"),\t   \"ResumingWorkOn\": $moment(payload.ResumingWorkOn).format(\"YYYY-MM-DD\"),\t   \"BackedUpBy\": payload.BackedUpBy,\t   \"HandoverBackup\": payload.HandoverBackup,\t   \"ContactAddress\": payload.ContactAddress,\t   \"ContactNumber\": payload.ContactNumber\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":1680,"wires":[["1019cbe995c63db0"]]},{"id":"c67030e5dfe0410a","type":"debug","z":"54efb553244c241f","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":1600,"wires":[]},{"id":"8200bbc2589ed62e","type":"ui_group","name":"Holiday Request","tab":"0add88570f6db7ad","order":2,"disp":false,"width":"20","collapse":false,"className":""},{"id":"0add88570f6db7ad","type":"ui_tab","name":"Admin View","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

Perfect !
I just didn't know where and how to incorporate the moment part !
Thanks a lot :slight_smile:

Fixed my issue

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