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!
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
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.
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.
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…
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