Jump to content

Time minus weekends


Crimpage

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.