Parse String and Format a invalid date

Hello guys! It is a pleasure to be here. I need help to format a date in a specific format…
I get the string as: DD MMM YYYY
Exemple: 11 Jan 2021
The problem is that it comes in Portuguese, and the initials of the month will not always work on the “date and time”

Exemple: 11 fev 2021
works if it is: 11 feb 2021

I thought of creating a function to do parse text and then immediately…

IF MMM = FEV
then FEB

and then mount a variable again

and do it for all the months I need … but I don’t know how to put it in a function

Can anyone help me with a solution?

Hey @Integra_Ninja!

Welcome to the community :slight_smile:

Are you getting the date in the format 11 fev 2021 or are you getting the date, month, and the year separately?

Thanks!
I am receiving a unique value.

“date”:“12 jan 2021”

Check the example below.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      date: '11 jan 2021'\n    }\n  },\n    {\n    json: {\n      date: '11 fev 2021'\n    }\n  },\n      {\n    json: {\n      date: '11 março 2021'\n    }\n  },\n  {\n    json: {\n      date: '11 abril 2021'\n    }\n  },\n  {\n    json: {\n      date: '11 maio 2021'\n    },\n   },\n   {\n      json: {\n         date: '11 junho 2021'\n       }\n    },\n       {\n      json: {\n         date: '11 julho 2021'\n       }\n    },\n           {\n      json: {\n         date: '11 agosto 2021'\n       }\n    },\n               {\n      json: {\n         date: '11 set 2021'\n       }\n    },\n                   {\n      json: {\n         date: '11 out 2021'\n       }\n    },\n                       {\n      json: {\n         date: '11 nov 2021'\n       }\n    },\n                           {\n      json: {\n         date: '11 dez 2021'\n       }\n    }\n    ]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        590,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "\nconst months = {\n  'jan': 'jan',\n  'fev': 'Feb',\n  'março': 'Mar',\n  'abril': 'Apr',\n  'maio': 'May',\n  'junho': 'June',\n  'julho': 'July',\n  'agosto': 'Aug',\n  'set': 'Sept',\n  'out': 'Oct',\n  'nov': 'Nov',\n  'dez': 'Dec',\n}\n\nfor (const key of Object.keys(months)) {\n  if (item.date.includes(key)) {\n      item.newData = item.date.replace(key, months[key])\n  }\n}\n\nreturn item\n\n\n//jan.\tfev.\tmarço\tabril\tmaio\tjunho\tjulho\tagosto\tset.\tout.\tnov.\tdez.\n//Jan.\tFeb.\tMar.\tApr.\tMay\tJune\tJuly\tAug.\tSept.\tOct.\tNov.\tDec.\n"
      },
      "name": "FunctionItem",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        840,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "FunctionItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}