I have a set of data which includes dates (e.g. October 28 2025), however some of this data is formatted as relative to now (e.g. 15 minutes ago, 2 hours ago, etc). These are all mixed together in the same dataset.
I want to convert all of the relative dates to absolute dates. I am not a coder, but I understand that Javascript or Python might be the best way to do this?
Does anyone have some experience with any of the above that could help me create a node to handle the conversion? Below I will paste a pinned set of data for experimentation and debugging.
Ultimately my goal is to get all the dates into the same format, and then use the n8n built-in Date & Time node to reformat them to yyyy-MM-ddThh:mm:ss. Although if someone knows how to include this formatting step in the Code block, that would be a bit more efficient!
There is nothing native that does this, There are some Python and JavaScript libraries you can use,or for simplicity, just create your own custom code logic..
However, it depends on what your relative dates format look like..
but anyway here is an example code that works for the pinned example you shared,
Feel free to edit it with your preferred AI, it should excel at these types of tasks:
This worked, thank you for sharing! I tried using Claude Sonnet 4.5 to generate JS code, but it kept failing to run within n8n. Which AI did you use btw?
For this, I used Claude as well,
The prompt is the key and how you imagine the solution looks like it,
Typically you just need to tell it what the inputs look like, then describe your problem, and finally specify the expected output.
Something like:
I'm using n8n and receiving relative dates like "2 hours ago", "3 days ago", or "Oct 29, 2025" in a field called property_date.
I need an n8n JS Code node that:
1. Converts these date strings to ISO format
2. Uses only built-in JavaScript
3. Returns the proper n8n format (array of objects)
4. Has the reference time (for calculating relative dates) defined at the top so I can easily change it