Work with dates

Hello everyone.
I'm try in "birth_date" and "today" remove the year. But I can't
Maybe, someone can help me??

[
    {
        "id": "b49747026544d0db",
        "type": "inject",
        "z": "211435c7c78b8aae",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"prt_t24id\":\"4906494\",\"phone\":\"3809300000\",\"upload_date\":\"19.07.2022 00:00:00.0\",\"birth_date\":\"1993-09-22 00:00:00.0\",\"code\":\"1\"}",
        "payloadType": "json",
        "x": 120,
        "y": 1220,
        "wires": [
            [
                "3fd37ee209d40aad"
            ]
        ]
    },
    {
        "id": "3fd37ee209d40aad",
        "type": "change",
        "z": "211435c7c78b8aae",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload.birth_date",
                "pt": "msg",
                "from": " 00:00:00.0",
                "fromt": "str",
                "to": "",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 215,
        "y": 1220,
        "wires": [
            [
                "69050c00f4c32acf"
            ]
        ],
        "l": false
    },
    {
        "id": "4b065176673818b2",
        "type": "function",
        "z": "211435c7c78b8aae",
        "name": "",
        "func": "msg.payload.birth_date = msg.payload.birth_date.split('-');\nmsg.payload.birth_date = msg.payload.birth_date.shift();\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 480,
        "y": 1220,
        "wires": [
            [
                "6beedd60de8eb073"
            ]
        ]
    },
    {
        "id": "69050c00f4c32acf",
        "type": "function",
        "z": "211435c7c78b8aae",
        "name": "",
        "func": "var todayDate = new Date(); \nvar _resultDate = todayDate.toISOString().split('T')[0]\nmsg.payload.today = _resultDate;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 320,
        "y": 1220,
        "wires": [
            [
                "4b065176673818b2"
            ]
        ]
    },
    {
        "id": "6beedd60de8eb073",
        "type": "debug",
        "z": "211435c7c78b8aae",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 1220,
        "wires": []
    }
]

You can format your dates using JSONata and $moment().
e.g.

[{"id":"b49747026544d0db","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"prt_t24id\":\"4906494\",\"phone\":\"3809300000\",\"upload_date\":\"19.07.2022 00:00:00.0\",\"birth_date\":\"1993-09-22 00:00:00.0\",\"code\":\"1\"}","payloadType":"json","x":130,"y":740,"wires":[["3fd37ee209d40aad"]]},{"id":"3fd37ee209d40aad","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload.birth_date","pt":"msg","to":"$moment($$.payload.birth_date).format(\"DD/MM\")","tot":"jsonata"},{"t":"set","p":"payload.today","pt":"msg","to":"$moment().format(\"DD/MM\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":740,"wires":[["6beedd60de8eb073"]]},{"id":"6beedd60de8eb073","type":"debug","z":"20bb0f7f9fab47a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":740,"wires":[]}]

https://momentjs.com/docs/#/displaying/format/

1 Like

thank you. it works

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