Errors trying to iterate node output to calculate minutes between first result and second result

Describe the issue/error/question

Efforts so far & thanks: Despite being incredibly simple, after 100’s of tabs researching & over 3 days of trying everything, we finally give up and so turn to the lovely people of this community in hope of a little assistance. Simply cannot express how deeply grateful I would be for absolutely any help whatsoever - have been pulling my hair out about this so cheers if you can spare a few minutes.

TL;DR: Iterate through the results of a Google Calendar node to calculate minutes between the first result and the second result (and so on,) with the aim of finding any minutes of space that is greater than the variable ‘event-minutes’ so that we can schedule that accompanying new event into the free time slot found.

Workflow notes: The below workflow gives a rough blueprint of the beginning of what we’re trying to achieve. At one point we had the workflow below calculating the time between end & start of the same event but that’s irrelevant as we need the ‘datecalc’ node to calculate the minutes between the end of the first result (event) against the start of the second result (event) - so as to calculate free time as opposed to the busy time. If the resulting minutes is less than the variable ‘event-minutes’ then it would need to calculate the minutes between the end of the second result (event) against the start of the third result (event,) and so on until it finds an empty time slot whose available ‘non-busy’ minutes is greater than the variable ‘event-minutes’ - allowing us to schedule into that free slot.

Apologies for that bearly coherent dribble but please do let me know if it didn’t make enough sense.

Many thanks in advance and warmest regards,


What is the error message (if any)?

Various errors depending on what was tried.

Please share the workflow

Share the output returned by the last node

n/a - no output achieved yet

Information on your n8n setup

  • n8n version: - can probably find out
  • Database you’re using (default: SQLite): - can probably find out
  • Running n8n with the execution process [own(default), main]: - can probably find out
  • Running n8n via [Docker, npm,, desktop app]: - via heroku whilst testing

Hey @binvius,
welcome to the community :tada:

I created a workflow that:

  • Gets All Calendar Events between start/end datetime (one day in example)
  • Parse Events to simplfy data we need
  • Calculate Free Slots between those events

Get All Events was a bit confusing because the options Start Time and End Time intuitively seem like they should be the other way around.

Parse events is just to simplify google calendars event data response.

Calculate Free Slots calculates the slots in between those events and calculates the minutes available. You would need to add a free slot at the beginning/end depending on the Start Time and End Time you are using to look for free slots

I hope this helps.

1 Like

I simply cannot express how thankful I am that you were so kind in helping out - it really means the world to me and I hope to one day pass on my knowledge as I develop further.

(My learning style is to deconstruct a working example and learn how it worked so what you provided was perfect and very valuable.)

Incidentally, I saw your response about 23 hours ago. During that time, I slept for 5 hours, ate food for 30 mins and relaxed for 30 mins, which totals 6 hours. Consequently, I have spent a whole 17 hours trying to implement what you kindly provided.

Hundreds of research tabs and dozens of complex attempts later, I now find myself wanting to be sick as a result of the extreme stress. I would therefore be extremely grateful if yourself or anyone could spare a few minutes to provide any further assistance regarding the logic side of things (as your kindly provided workflow already does exactly what I initially requested.)

Your workflow worked perfectly and filled up all the empty space in the first free block of time (i.e the first result in the array/index of the ‘parsePositveNumbers’ node below.) However, because it added an event to the calendar that overlapped an event already there, I tried to add in some logic with the ‘blockDuration’ node below.

The issue I’m facing is trying to use an incrementing counter to force use of the next free block of time (i.e the second result in the array/index of the ‘parsePositveNumbers’ node below.)

Ultimately, the flow I’m eventually trying to achieve is:

  1. Find free space on Google Calendar so that I can fill that space up with events from Notion events database.
  2. a - If the space remaining (in current Google Calendar free block being processed - index 0 of parsePositveNumbers node) is not large enough to accommodate the current Notion event duration, move to processing the next Google Calendar free space block (index 1 of parsePositveNumbers node.)
  3. b - Or even better, iterate through remaining Notion events database to find an event with a duration that can fill that remaining Google Calendar space, before returning back to the Notion event that didn’t fit and see if it fits in the next Google Calendar free space block (index 1 of parsePositveNumbers node.)
  4. If 2. b above was not achievable, there will be empty spaces on the Google Calendar left over from 2. a, so fill them up with items from the Notion events database.

The stress has been so high, at this point I’d be happy to pay someone to help out with a working example (that I can learn from) but any help at all would be deeply deeply appreciated.

Warmest regards,


Below is a very stripped-down version of one of my previous attempts (should it help illustrate my intentions at all:)

(Note: I use timeblocking so set a number of timeblocks in Notion (property_blocks_net) and then calculate the ‘duration’ by multiplying that number of timeblocks by 15 minutes.)

1 Like

Hey @binvius,
right now I do not have a workflow ready for your usecase. It seems like you are looking for an optimal strategy how to fill free calendar slots with a list of booking requests with different durations. That is not an easy task to do. Try to solve a simple and straightforward approach first, like booking the first avalaible slot for each booking request.

It would also be helpful if you could build a POC workflow using fake data with a function node at the beginning. Pasting your workflow into the community forum really helps, but in your case we do not see the Notion document your solution is based on.

If you are looking for experts to hire you can also checkout our n8n experts page.