How to add data to function node?

How do I add data from an incoming node to be used in a function node?

I feel like I did 95% of the work but can’t figure out the simplest of things any insight would be amazing.

So, as you can see the flow is very simple, take 2 dates and calculate the number of days in between both dates.
at this moment I have the flow working with dummy data in the function node and just can’t figure out how to get the real dates to be placed instead of the dummy data

Ok, this question seems very basic (maybe that is why I couldn’t seem to find the answer in the documentation.

Try this:

2 Likes

Hey @David_Go, you can read incoming data as described in these examples from the Function node documentation. It also supports all expressions (you wouldn’t need the curly braces around them in this case).

Edit: @Shirobachi beat me to it, so please ignore my example below :smiley:

So a simple example populating your variables date1 and date2 using the incoming data from your Merge node could look like so:

Example Workflow
2 Likes

It maybe be helpful visualization, but since @MutedJam shared docs I would also suggest read it, it suck of good content!


Be aware that you always need to return one array of object, each object has to have json property what needs to be another object with your data

@David_Go Also you may want use external library to count time like moment or date fns

Have fun :slight_smile:

2 Likes

@MutedJam - Thank you so very much for your help on this, this just opened up a whole new world in n8n for me. Works like a charm !

@Shirobachi Thanks for the helpful insight :slight_smile: and I am totally having a blast with n8n! there is not a day that goes by without n8n and it just seems to be getting better and better each and every update that comes out.

2 Likes