Duration from date/time (day, evening, night shifts)

Hi all,

have a brain melting issue with calculating duration of time from a session as it progresses across into multiple session types! any help will be greatly appreciated, see details below.

Current situation:
i have a session booking tool that can select anytime of day as the start and end of session, using a date/time picker:
I can calculate a duration in minutes of the total session using the formula below:

The issue:
i have multiple types throughout the day at different pay rates (ie. weekday, evening, and night), these are categorised as:
Weekday - 6:00am to 8:00pm
Evening - 8:00pm to 12:00am
Night - 12:00am to 6:00am
i need to calculate the duration of each session within each type, can this be done in bubble?

for example:

  • a session booked from 10:00am to 1:00pm will calculate total duration as end time minus (-) start time. this is easy due to the entire session being within one type.

the problem comes up as a session runs over two types:

  • a session booked from 7:00pm to 10:00pm will need to calculate a duration for weekday (60 minutes) and Evening (120 minutes).

Any assistance with this would be hugely appreciated!


I see that no one has responded so … although I don’t have a complete solution, here’s my first thought.

Create Duration (or ServiceDuration if you like) as a data type.
SessionType (weekday, evening, night)

In the Session data type, create a field that is a list of ServiceDuration.

This gives you a way to store each segment of a session.

What I haven’t thought through is how to determine how much of a full session’s duration is in each session type. It’s doable and I would have no trouble doing it in a procedural language like Visual Basic, but I’d have to noodle some to come up with the way to get it done in Bubble.

Good luck.

Thanks very much for your input @laurence,

i have managed to create a solution, on completing the session i would firstly put in the session completed time, then manually calculate each time category based on whether the start or end time was inside, outside, or within both of its category (ie. night, evening, or day) start or end time, see pics below:

the first pic shows the calculation for night duration (start of session is within night category).
the next shows the calculation for night duration when the end of the session falls within the night category.
next shows the calculation for night duration if the start time is before this category and the end is after this category.

i did these calculations for each time category (night, evening, weekday) and then multiplied this out by the cost per hour for each; which was then actually calculated for each minute!
most of the time these categories would be empty, but they need to be calculated due to the varying session end time.

hope this helps someone out there!

if anyone wants anymore detail, feel free to msg me!


1 Like

I knew I was late to the party but the problem is near and dear to what I’m working on so I thought I’d jump in. Glad you got it solved.

This topic was automatically closed after 70 days. New replies are no longer allowed.