Crimpage Posted March 30, 2009 Share Posted March 30, 2009 Hi Everyone, I'm generating a report that pulls data from our IT Support helpdesk software, and the report detirmines how long each request has been open for. I need it to work out the date minus any weekends that may have been involved. For instance, say a job was opened Thursday 4:00PM and was closed on Tuesday 10:00AM, that totals 90 hours or 5400 minutes. I need it to check and see if each day it was open was a saturday or sunday and if so, remove that from the total time open. so 90 hours would be - 48 for the weekend = 42 hours = 1.75 days open. The three details I will have to work with are the Created / Open date and either the Completed date, or if it is still open, the time right now. Thanks for your help. David Quote Link to comment https://forums.phpfreaks.com/topic/151674-time-minus-weekends/ Share on other sites More sharing options...
cunoodle2 Posted March 30, 2009 Share Posted March 30, 2009 What format are your dates in? Is it the epoch unix time stamp or mysql date format? Here is how I would do it (in plain english). You will have to translate into php/mysql depending on how you have it stored. <?php $weekend_days = 0; $start_date = //start of ticket time here; $end_date = //end of ticket time here; $start_date + 1Day = $current_working_Day; while ($current_working_day < $end_date) { if (GET_DAY_OF_WEEK[$current_working_day] == "saturday" OR == "Sunday") $weekend_days ++; $current_working_Day + 1Day = $current_working_Day; } $end_date - $start_date = $total_days; $total_days - $weekend_days = $total_days; ?> I know that is VERY rough code and that would throw out about 1,000 php errors but it should give you a pretty good idea on what to start with. You could also figure out the number of minutes between start time and end time and then subtract "$weekend_days * 1440 [number of minutes in a day] to get the total number of minutes. Then convert the minutes into whatever format you wanted to. Its a pretty safe bet that your tickets will have zero weekend days, 2, 4, 6, 8 etc... There is no way your tickets will ever had an odd number of weekend days as no one is working on Sat and sun. If someone does solve the ticket on sat and sun then there is no need to even have this formula in the first place. Get some code working and I'll help finish it off. In all cases I ask that you post your fully working completed code at the end to help another future user. Quote Link to comment https://forums.phpfreaks.com/topic/151674-time-minus-weekends/#findComment-796577 Share on other sites More sharing options...
corbin Posted March 30, 2009 Share Posted March 30, 2009 http://www.phpfreaks.com/forums/index.php/topic,224493.0.html Is kinda related, although it looks like cunoodle2 answered your question. Quote Link to comment https://forums.phpfreaks.com/topic/151674-time-minus-weekends/#findComment-796580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.