# Work with dates

**URL:** <https://discourse.nodered.org/t/work-with-dates/68124>\
**Category:** General\
**Created:** [23 September 2022 09:11 UTC](https://discourse.nodered.org/t/work-with-dates/68124 "2022-09-23T09:11:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jen](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@Jen](https://discourse.nodered.org/u/Jen)\
**Post date:** [23 September 2022 09:11 UTC](https://discourse.nodered.org/t/work-with-dates/68124/1 "2022-09-23T09:11:46Z")

</div>

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

```auto
[
    {
        "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": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [23 September 2022 09:39 UTC](https://discourse.nodered.org/t/work-with-dates/68124/2 "2022-09-23T09:39:54Z")

</div>

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

```auto
[{"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/](https://momentjs.com/docs/#/displaying/format/)

---

<div class="post-metadata">

**Author:** ![Jen](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@Jen](https://discourse.nodered.org/u/Jen)\
**Post date:** [23 September 2022 11:40 UTC](https://discourse.nodered.org/t/work-with-dates/68124/3 "2022-09-23T11:40:09Z")

</div>

thank you. it works

---

<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:** [22 November 2022 11:41 UTC](https://discourse.nodered.org/t/work-with-dates/68124/4 "2022-11-22T11:41:01Z")

</div>

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