Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: Date and time difference
01-21-2004, 09:59 PM #1
- Join Date
- Jun 2002
- Thanked 0 Times in 0 Posts
Date and time difference
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:
// 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.
// makes the dates and times into unix timestamps.
$first_unix = mktime($first_hour,$first_min,$first_sec,$first_mo
$second_unix = mktime($second_hour,$second_min,$second_sec,$secon
// Gets the difference between the two unix timestamps.
$timediff = $first_unix-$second_unix;
// Works out the days, hours, mins and secs.
// 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' ) ;