Issue with Date Comparison – Works in “Test Step” but Fails in “Test Workflow”

Describe the problem/error/question

Hi everyone,

I’m facing an issue with date comparisons in n8n. When I test a single node using “Test Step”, everything works as expected. However, when I run the entire workflow using “Test Workflow”, I get unexpected errors related to date formatting.

I’m making sure to properly format the dates before comparing them. Specifically, I use Luxon to normalize them like this:

{{ DateTime.fromISO($json.subscriptionEnd).toUTC().startOf('day').toISODate() === DateTime.now().plus({ days: 7 }).toUTC().startOf('day').toISODate() }}
( Using the Node if of course )

Yet, I still get inconsistent results when running the full workflow. It seems like n8n is handling the dates differently depending on whether it’s a single step test or a full workflow execution.

I also tested using a Switch node for the comparison, and the issue remains exactly the same.

Has anyone encountered this issue before? Is there something specific about how n8n processes dates in full workflow runs that I should be aware of?

Thanks in advance for any help! :rocket:

What is the error message (if any)?

Problem in node ‘If one week‘

Conversion error: the string ‘Invalid DateTime’ can’t be converted to a dateTime [condition 0, item 0]

Please share your workflow

Information on your n8n setup

  • n8n version: 1.83.2
  • Database (default: SQLite): postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker (Portainer)
  • Operating system: Synology DS923+

Sometime I get this issue with this configuration

Issue :

Conversion error: the string 'Invalid DateTime' can't be converted to a dateTime [condition 0, item 0]
Try changing the type of the comparison.

I really don’t understand, as when I am on it, it shows that [DateTime: 2025-03-31T00:00:00.000Z] is a datetime. And using Test step works… I feel lost.

Shouldn’t this be 'day'?

Working with dates can be tricky esp. when multiple systems are at play. DateTime as a String or of DateTime type, conversions of data between nodes, timezone at DB server, n8n server and browser.

I guess DateTime becomes a string when data is passed over from node to node. Hence the parsing and conversion challenges. See e.g. warning here: Date and time with Luxon | n8n Docs

Can you repost the workflow with data from MongoDB node pinned?
This might provide some insights into the datetime field actual format.

Yes you’re right, but in my code this is right avec verification… I may have put it wrong when sending.

Here is the actual with Switch.

These are the data I get from mongodb:

[
  {
    "_id": "67d9928776cda976ae6570cb",
    "name": "Aude",
    "surname": "*****",
    "email": "",
    "subscriptionEnd": "2025-03-31T15:23:10.959Z"
  },
  {
    "_id": "67d9a965e1fdcebbb67c1358",
    "name": "Fanny",
    "surname": "*****",
    "email": "",
    "subscriptionEnd": "2025-03-31T15:23:10.959Z"
  },
  {
    "_id": "67d9a974e1fdcebbb67c1359",
    "name": "Johan",
    "surname": "*****",
    "email": "",
    "subscriptionEnd": "2025-03-31T15:23:10.959Z"
  },
  {
    "_id": "67d9a97fe1fdcebbb67c135a",
    "name": "Katia",
    "surname": "*****",
    "email": "",
    "subscriptionEnd": "2025-03-31T15:23:10.959Z"
  },
  {
    "_id": "67d9a98de1fdcebbb67c135b",
    "name": "Noa",
    "surname": "*****",
    "email": "",
    "subscriptionEnd": "2025-03-31T15:23:10.959Z"
  },
  {
    "_id": "67dab4fff07458398a8ddfe8",
    "name": "Jacques",
    "surname": "Nexistepa",
    "email": "[email protected]",
    "subscriptionEnd": "2025-03-26T15:23:10.959Z"
  }
]

I tried to reproduce, emulating MongoDB output.
I obtain exactly same outcome whether I test WF in a one go or step-by-step.

Switch node won’t allow to pin data. So here is the distribution across Switch output branches:

  • Un jour restant: none
  • Une semaine restante (1 item): Jacques
  • Fallback (5 items): Aude, Fanny, Johan, Katia, Noa

UPDATE: note how Swtich compares dates as strings (this peculiarity was inherited from your workflow).

UPDATE2: I was able to reproduce the error when comparison is set to Date&Time equals to and any input date is null. So, maybe you receive nulls from MongoDB in some circumstances? Just a blind shot. Is there a way to log MongoDB outputs in failing scenarios?

Your reply gave me an idea, using the Code node. So now it transforms the data inside the code and add 2 new data in each “user” : nextWeekIs and todayIs, so I can compare these 2 strings and if equals, then do the rest…

It seems to be the best solution actually for me.

2 Likes

Glad you managed to solve it. I think storing the transformed dates is a great idea as you won’t need to do transformations on the fly when checking conditions next time. I would even vote for storing e.g. subscription end date as yyyy-mm-ddzT23:59 or even next day midnight (indicating end of the last day) when creating the record for the subscription.

Yes that was necessary, so I don’t have to format it later, this is very helpful. I added the date in french, so it is readable for my non english speaking friends :wink:

So now complete data looks like this:

[
  {
  "_id": "67d9928776cda976ae6570cb",
  "name": "Aude",
  "surname": "Jacquinette",
  "email": "[email protected]",
  "subscriptionEnd": "2025-03-31",
  "subscriptionEndFR": "31 mars 2025",
  "todayIs": "2025-03-20",
  "inTreeDaysIs": "2025-03-22"
  }
]
1 Like

Sanitizing and normalizing data early is always a good idea :+1:

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