Invalid Date format when it worked well before

Describe the problem/error/question

I have been converting my scenario from Make to N8N, node by node, and I stumbled unto a problem today, that wasn’t happening yesterday.
The date is now invalid. I use a day/month/year format and it was running fine until today.
I even set a Extract Part of a Date (Year) and it worked fine. I thought maybe ChatGPT returned an invalid character or something, so I changed it to dd-MM-yyyy instead of “/”. I trimmed the input in case there was a space. Still nothing.

After some trial and error, I prompted ChatGPT to respect the date format, it worked and set a Format a Date node, using the function:

{{ DateTime.fromFormat($json.message.content.fecha_emision, ‘dd/MM/yyyy’) }}

Custom format: dd/MM/yyyy
And It works!

BUT: After that node, I wanted to get the year part. It fails with “Invalid Date Format”.

¿How can I correct this?

P.S.: I don’t know how to paste my scenario without showing sensitive data…


Information on your n8n setup

  • n8n version: 1.84.3 (Self Hosted)
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system: Windows 10 Pro

Stack trace

NodeOperationError: Invalid date format at ExecuteContext.parseDate (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/DateTime/V2/GenericFunctions.js:46:19) at ExecuteContext.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/DateTime/V2/DateTimeV2.node.js:189:69) at WorkflowExecute.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:681:50) at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:913:62 at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/execution-engine/workflow-execute.js:1246:20

You can create a copy of your workflow then execute it, pin data that is important to understand workflow and even edit replacing sensitive data with some random characters.

Then you copy this workflow and paste it here using the </> button.

Between nodes the dates are converted back to strings, so you need to parse it again and extract the part you need.
DateTime.fromFormat(fieldName, 'yyyy').year

If the above answers your question, please mark this post as a :white_check_mark: Solution.

1 Like

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