Invalid DateTime in Set node with DateTime() function

Hello everyone. I need help.

I have 7 different dates in format MM/DD/YYYY. But I need another format DD.MM.YYYY. I want to change format in Set node because I don’t want my workflow to be bulky with 7 Date & Time nodes. But I get this issue:
image

My Set node input:

Also I have to delete expressions with date < 01.01.1900. Maybe I can do both tasks with Code node, but Im pretty bad with JavaScript. Maybe You can help me?

Information on your n8n setup

  • n8n version: 0.224.4
  • Database: SQLite
  • n8n EXECUTIONS_PROCESS setting: main
  • Running n8n via: Docker Compose
  • Operating system: Ubuntu

Hi @Eventurum, I am sorry you’re having trouble.

tl;dr: you probably want to use this expression

{{ DateTime.fromFormat($json["PM clinic"], 'L/d/yyyy').toFormat('d.LL.yyyy') }}

Full explanation:

In an n8n expression (and JavaScript in general), the single quotes ' would indicate the beginning and end of a string. So in an expression like DateTime.fromFormat('$json["PM clinic"]', 'L/d/yyyy'). n8n would try to parse a string of $json["PM clinic"] which fails.

If you don’t use the quotes, n8n would parse the value of your PM clinic field instead. Here’s an example workflow showing this:

This is the result:

Hope this helps!

As for your second question, deleting dates before 1900, can you confirm what exactly you want to delete? Do you want to remove the entire item or just the specific value?

Hello @MutedJam, thank you for your reply.

Your answer about DateTime() helped me a lot.

As for the second question:
I want to keep only Inspections which were made after 01.01.1900. So I want to remove values which < 01.01.1990

1 Like

In this case I think the easiest approach would be to first parse the date, then use the IF node to check if it was before 1990. Here’s an example, filtering the Bucket Inspection field (you can of course change this and add more conditions for additional fields as needed):

You can see that only the item with a Bucket Inspection date after 1990 would pass the IF node here:

Hope this helps!

2 Likes

Thank you so much!

1 Like

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