Different output for identical inputs - bug with the system or my mind?

Describe the issue/error/question

Using a function to work out the date for yesterday, I think has always worked. But today, which is the first day of the month, I noticed a stange output.

The workflow attached outputs the correct result of ‘2022-06-30’ for var one but outputs ‘2022-05-31’ for var two, even though they are both defined identically with (curr.getDate()-1)

It’s probably a bug with my mind but it’s driving me mad - lol.

What is the error message (if any)?

No error, just unexpected maybe.

Please share the workflow

Share the output returned by the last node

none

Information on your n8n setup

  • n8n version: um
  • Database you’re using (default: SQLite): um
  • Running n8n with the execution process [own(default), main]: um
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: online

Well that has hurt my head, For fun I have tried to run the same thing in the browser console and I get the same “broken” result. I think this is going to be some javascript oddity but I am not sure why it happens.

On the plus side… It doesn’t look to be an n8n bug as it can be reproduced outside of n8n and it doesn’t look to be something wrong with your mind.

If it makes life a bit easier for you to get the previous day you can also use Luxon with $now.minus({days: 1}) or if you don’t need the exact time you can replace now with today.

That is good news though that it’s not an n8n bug - hopefully less work for everyone then.

I tried using luxon in the past but need to improve my skills.

I just tried the $now.minus({days: 1}) but not getting it to work in my messy function. Do you know if it can output a specfic time, say midnight yesterday? (I’m assuming I’d use it in a Function and not a Set node, right?)

A specific time time should be all good, It looks like Luxon has a set option. luxon 2.4.0 | Documentation

When it wasn’t working did it have an error?

@Jon

I worked it out! Thanks for guiding me.

If anyone happens across this thread in the future and to help minimise repeat questions, the luxon I used to get midnight to midnight of yesterday, is:

Hope that helps.

1 Like