How do you adjust Luxon settings in an Expression?

I’m receiving date data that is in MM/dd/yy format (that is Dec 31st 1954 is written as 12/31/54). Luxon is capable of handling 2 digit years, but assumes the cutoff year is 1960 by default, so in the above example, my incoming date would be parsed to mean Dec 31st, 2054.

Luxon documents that Settings.twoDigitCutoffYear is a configurable value, but I don’t know how to do that configuration in N8N as part of an Expression. I would want it to be one value of incoming birthdates (‘24’), for example, and a different value for expiration dates (the default ‘60’ would probably work here).

Can anyone point me to the right technique for invoking this kind of Settings change?

Hey @Ian_Walls,

I have been having a play with this and I can’t get the option to work so I suspect a code node could be the only way to handle that. Outside of that what about using an if node to work out if the year is larger than 60 but smaller or equal to the current year then using that to subtract 100 from the year.

The example below will do that and I have added 4 dates for testing, There are some possible issues like if all of your dates are pre 2000 but in that case you could just subtract 100 from them all


Thanks, Jon! I took your technique, and combined it all into a single expression:

{{($json.birth_date.slice(-2) < 61 && $json.birth_date.slice(-2) > 23) ? DateTime.fromFormat($json.birth_date, "MM/dd/yy").minus({years: 100}).toISODate() : DateTime.fromFormat($json.birth_date, "MM/dd/yy").toISODate()}}

That ‘23’ may need adjusting to catch folks over a century old, but I’ll leave that to the person who knows the data itself.


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