Forum Academy Marketplace Showcase Pricing Features

Exclude certain hours from a calculation

Following on form this response

I am still not sure how to achieve a “similar” outcome. I have some events that span over a few days. A single day event is easy to calculate with subtraction, but how would I best approach the following scenario.

An events starts at 08:00am on Monday and ends at 05:00pm on Tuesday (or Wed, etc) how would I calculate just the 8-5 hours for each day? Its breaking by brain

Any thoughts?

I would save different values to your database which you can use later.

  1. save start date

  2. save end date

  3. now its more difficult: save date range first day from 8 to 5 on monday and date range from 8 to 5 on tuesday and save them to a list of date ranges. Then later calculate those values.

For step 3 you have to go with conditionals such as:

If starting date is > 7:59 and < 5:00 → set first start date

if end date > 5:00 → set end date to monday 5:00

if start day != endday set enddate monday 5:00 and startdate second to 8:00

something like this came to my mind when reading your post….

Thanks David, will give it a go and report back