F1Fan,
Thanks for the info. Below is the full working script. It hert my brain but i fixed it.
// Query database
$monthago = time() - ($days * 24 * 60 * 60);
// TESTING with the Arrays ForEach!
$value = pg_exec("SELECT * FROM tbl_issues WHERE status LIKE 4 AND createdon NOT LIKE closedon AND project LIKE 0 AND createdon > " . $monthago);
//array_push($timeArray, pg_fetch_row($value)); // push all of the values into an array
$i = 0; // Set $i
for($row = 0; $row < pg_num_rows($value); $row++) {
$closed = pg_result($value, $row, 'closedon'); // timestamp it was closed
$created = pg_result($value, $row, 'createdon'); // timestamp it was created
$timeTook = $closed - $created;
// MAKE SURE DAYS ARE ONLY 8.5 HOURS
// If its greater than 24 hours
if (isset($timeTook) && $timeTook >= 86400) {
// Divide the number by 24 hours to find out how many days
$daysAmmount = ($timeTook / 86400);
// Work out the ammount of hours to subtract
$hoursToSubtract = (55800 * $daysAmmount);
// Subtract the subtraction hours from the total hours available
$calDays = $timeTook - $hoursToSubtract;
} else if ($timeTook >= 30600 && $timeTook <= 86400 ) {
//If the time it took to close a job it between 8.5 and 24 hours then set it to 8.5
// for the job to be closed
$calDays = 85000;
} else if ($timeTook <= 30600) {
//if the time it took to close a job is less than 8.5 hours then no need
// to calcualte the times
$calDays = $timeTook;
}
//$timeTook = (($timeTook/60)/60);
// TAKES AWAY WEEKENDS IF THEY ARE THERE
while ($calDays > 0) {
// 55800 = 15.5 Hours!
// 604800 = 168 Hours!
// 432000 = 120 Hours!
// 86400 = 24 Hours!
// 30600 = 8.5 Hours!
//echo $calDays. "<br />";
if (isset($calDays) && $calDays >= 604800) {
$calDays = $calDays - 604800; // Take away the full week
//$totalTime = $totalTime + 120000; // turn it intop 5 days
$totalTime[$i] = $totalTime[$i] + 432000;
$i++;
} elseif ($calDays >= 432000 && $calDays <= 604800) {
$sum1 = $calDays - 432000; // Find out how much hours are left after 5 days
$sum2 = 432000 - $sum1; // Take the ammount in $sum1 from 5 days of hours
$calDays = $calDays - $sum2;
//$totalTime = $totaltTime + $sum2; // turn it intop 5 days
$totalTime[$i] = $totalTime[$i] + $sum2;
$i++;
} elseif ($calDays <= 432000) {
$totalTime[$i] = $totalTime[$i] + $calDays;
$calDays = $calDays - $calDays;
//$totalTime = $totalTime + $calDays;
$i++;
}
}
}
$average = array_sum($totalTime) / count($totalTime);
//echo "<br /> Aver Job Completion Time: " . $average . "<br />";
//echo " TOTAL HOURS AFTER EXPANDED: " . $totalTime . "<br />";
// Put the value into format
// Handle errors
if (!$average) {
echo 'Query failed';
} else {
$time = $average;
if ($time < 60) {
$seconds = floor($time);
echo $seconds . ' seconds';
} elseif ($time < 3600) {
$minutes = floor(($time / 60));
$seconds = floor($time - ($minutes * 60));
echo $minutes . ' minute(s) and ' . $seconds . ' second(s)';
} else {
$hours = floor((($time / 60) / 60));
$minutes = floor((($time / 60) - ($hours * 60)));
echo $hours . ' hour(s) and ' . $minutes . ' minute(s)';
} #else {
#$days = floor(((($time / 60) / 60) / 24));
#$hours = floor(((($time / 60) / 60) - ($days * 24)));
#echo $days . ' day(s) and ' . $hours . ' hour(s)';
#}
}
?>