Difference in Business Hours
I'm looking to get the difference in 'business' hours between two date/time fields. The business hour range is 9:00 - 17:00 (or 9am - 5pm), within weekdays.
Additionally, If a user enters a Start Date after 17:00, the start date should get pushed to 9:00 of the next business day.
For example, the following should have an output of 11 hours.
Start: 01/04/2022 11:00
END: 01/05/2022 14:00
I'm guessing this has been encountered quite a few times in the past, can anyone share what they've put together, even if it is just a starting point where I can adjust to my dataflow?
I am looking to perform this within a Beastmode.
I attempted using the solution within the topic listed below but am getting inconsistent results. https://dojo.domo.com/discussion/10059/how-can-i-show-an-age-between-2-time-stamps-in-business-hours
Answers
-
This is an interesting one. I started sketching something out and there are a lot of scenarios to account for. I think you will need multiple nested case statements and you would use the WEEKDAY(), DATEDIFF(), and HOUR() functions to help with doing the math. I'll see if I can come up with something workable over the weekend. If you haven't already looked at this post, this may help you as well.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.1 -
I think I have something for you to get your started.
/* check to see if the start hour is too late */ (CASE WHEN HOUR(`startdate`) >= 17 THEN ((UNIX_TIMESTAMP(`enddate`) - UNIX_TIMESTAMP( /*move it to the next day and start at 9 */ ADDTIME(ADDDATE(DATE(`startdate`), interval 1 day),9*60*60))) / 3600) ELSE /* subtract and then divide by 3600 to get the hours */ ((UNIX_TIMESTAMP(`enddate`) - UNIX_TIMESTAMP(`startdate`)) / 3600) /* if there is a difference in days, subtract 16 hours per day */ - (DATEDIFF(`enddate`,`startdate`)*16) END )
You will need to add some additional case statements to deal with weekends by using the WHEN WEEKDAY(startdate) IN (1,7) which is Sunday and Saturday as I wasn't sure how you want to handle those. Hopefully the above makes sense. For a deeper dive into unix_timestamp, you might want to look at this post.
https://dojo.domo.com/discussion/52682/domo-ideas-conference-beast-modes-time-difference-formatting
With my testing this is what the above beast mode produces.
Hope this helps.
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.5 -
Those are some nice links you have there @MarkSnodgrass :)
You can leverage the logic outlined in the links he's provided to calculate the difference in the number of full days in between your two days, then multiply those days by the number of hours in your day (8) then add in the number of partial days (hours) from your start (17 (5pm) - greater(hour of start or 9am) and end dates (least of 5pm or hour of end time) - 8 (8am)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
@Mario how did this go for you? Did this solve your problem?
**Check out my Domo Tips & Tricks Videos
**Make sure to any users posts that helped you.
**Please mark as accepted the ones who solved your issue.0 -
@MarkSnodgrass what would this beastmode look like if you were to only get the business hours for Monday - Friday, not every day?
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive