Forum Academy Marketplace Showcase Pricing Features

Time difference - number of working hours between two date/time elemenets

Hi folks. I am working on a time tracker app and really need some help.

What I want to have is two date/time picker elements where the user can select start date and time for a project and then end date and time for that project. Based on those dates and times I would like to have an output which will be the number of working hours between those two dates.

So lets say my working days are Mon-Friday 9:00 to 18:00 - so I have 5 working days and each day is 9 working hours.

So if a user picks start date to be a Friday at 11:00 and end date to be Tuesday 16:00 the result that I need is 23 hours (because I exclude weekend and also I don’t want to count hours outside of working hours)

Please any ideas on how to do this will be extremely appreciated !!!

Date/time 2’s value - date/time 1’s value:extract days * 9

1 Like

No offense to one of the best Bubblers out there, but I think it’s going to be more complicated than what Jared suggested. First off, can we assume a user’s working days/hours won’t always be Monday through Friday from 9am to 6pm? Also, is it possible for a user to include Saturday and Sunday in their working days and exclude two other days of the week?

In order to do what you described, I think you might have to store each day and its associated hours that a user works as a separate thing in a data type so you can use those things to figure out partial hours on days when the entire span of a user’s working hours is not covered. To take weekends out of the mix, you could think about doing something like what I described in this tip I wrote a few years ago, but maybe someone knows a much better way to do that.

Anyway, unless I am missing something, I think this one’s a bit tricky, and the stuff I threw out there is really just food for thought at this point.

Hope this helps.


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