Error in a workflow shared from n8n it self

Describe the problem/error/question

I am currently doing the Level 2 course and am on the Data Exercise example on the Processing different data types | n8n Docs website. I copied the JSON and wanted to try out the code, but the IF statement is not working. Every time I get an error saying that it is a string and does not match the date-time. I haven’t changed anything in the code and would like to understand how to solve this. In addition, the code offered as a solution in the course itself should work. Please be patient with me, I am completely new to this whole Space.

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

hello @Gregor

I’ve just copied the workflow and didn’t get any issues. Can you show the error screen?

1 Like

i always gets this error… made a new project copied the code and always this issue

The issue is in the node before. You can see that the date is not valid. Check the Date & Time node

Hey @Gregor, try this in the If node:

{{ $json[‘new-date’].toDateTime() }}

This should fix the DateTime error! Let me know if it works .

so that’s the node before what am i doing wrong?

it says invalid syntax :slight_smile:

Check the Date & Time settings page. Is it version 2 or 1? Those fields should be correctly set

Sometimes the execution gets broken, so it’s better to clear the execution and start the workflow over

Lets explain the problem, the answer is string and invalid

use:

{{ new Date($json["new-date"]) }}

compare with

{{ new Date("1960-01-01T00:00:00") }}

the output should be:

1960-01-01T00:00:00

***********
so, the best solution in n8n is:

{{ $json["formattedDate"] }}

********
think about your data (string, number, Boolean, dateTime)

hey @Gregor welcome to the forum! So barn4k spotted it right, the issue is actually happening in the Date & Time node before the IF, not in the IF itself. When you see “Invalid Date” showing up in that preview that means the conversion already failed upstream and then the IF node is just complaining because it’s getting garbage instead of an actual datetime object.

The thing with that course workflow is it was probably built on an older n8n version and the Date & Time node has gone through some changes, so sometimes the field references or format strings don’t quite match up anymore. Open up your Date & Time node and check what field it’s trying to read from and what format it expects, then compare that against what’s actually coming in from the previous node. Usually it’s either the field name is slightly off or the incoming date string format doesn’t match what the node is configured to parse.

If you want to skip messing with the Date & Time node entirely you can do what Msquare suggested and just use `.toDateTime()` directly in your IF condition on the raw date string, that’s often easier than trying to get the Date & Time node config exactly right.

Guys i found the mistake on my own. I think it was cause on my settings the Timezone was on Default. Where can i change this globally? I need to change this on every Workflow. After i changed this to my TZ the workflow is working haha

2 Likes

What are your environment variables?
Seems you didn’t properly set the env GENERIC_TIMEZONE
Set the self-hosted instance timezone | n8n Docs

1 Like

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