I found this script on another forum for calculating the difference between two dates and times. I made some minor modifications and it works great. I am going to use this in a help desk application to report on how long it takes from the date and time a support request is initiated until it is responded to by a support tech and also until it is closed. The problem is I need to figure out a way to not include the hours/days that support techs are not at work. This reporting will be used by there supervisor in their annual evaluations and it would not be fair to inlcude those hours in the time it took to complete a support request. So for example if a request was initiated at 4:00pm and not completed until 8:00am the next day then because our hours of operation are from 7:00 am to 5:00pm the hours to complete should be 2 not 16. Any ideas on how to accomplish this would be appreciated. If you can only give me ideas and not code that would be helpful. Thank you. Here is the script:


PHP:
--------------------------------------------------------------------------------

<?php
function date_diff($first_date,$first_time,$second_date,$se
cond_time)
{
// Author: Tone.
// Date : 15-12-2003.

// Ref: Dates go in "YYYYMMDD".
// Ref: Times go in "HHMMSS".
// Ref: mktime(HOUR,MIN,SEC,MONTH,DAY,YEAR).

// Splits the dates into parts, to be reformatted for mktime.

$first_hour=substr($first_time,0,2);
$first_min=substr($first_time,2,2);
$first_sec=substr($first_time,4,2);
$first_year=substr($first_date,0,4);
$first_month=substr($first_date,4,2);
$first_day=substr($first_date,6,2);

$second_hour=substr($second_time,0,2);
$second_min=substr($second_time,2,2);
$second_sec=substr($second_time,4,2);
$second_year=substr($second_date,0,4);
$second_month=substr($second_date,4,2);
$second_day=substr($second_date,6,2);

// makes the dates and times into unix timestamps.
$first_unix = mktime($first_hour,$first_min,$first_sec,$first_mo
nth,$first_day,$first_year);
$second_unix = mktime($second_hour,$second_min,$second_sec,$secon
d_month,$second_day,$second_year);

// Gets the difference between the two unix timestamps.
$timediff = $first_unix-$second_unix;

// Works out the days, hours, mins and secs.
$days=abs(intval($timediff/86400));
$remain=$timediff%86400;
$hours=abs(intval($remain/3600));
$remain=$remain%3600;
$mins=abs(intval($remain/60));
$secs=abs($remain%60);

// Returns a pre-formatted string. Can be chagned to an array.
return $days." days, ".$hours." hours, ".$mins." mins, ".$secs." secs.";
}
echo date_diff( '20040101','091130','20040119','091131' ) ;
?>