Forum Moderators: coopster
$howmany = 0;
$adddays = 0;
$rectime = "SELECT jobdate, completedate FROM jobs WHERE completedate!= 'NULL'";
$qrectime = @mysql_query($rectime);
while ($rect = @mysql_fetch_array($qrectime)) {
$howmany = $howmany + 1;
$datein = $rect["jobdate"];
$jobdone = $rect["completedate"];
$dateinu = strtotime("$datein");
$jobdoneu = strtotime("$jobdone");
$turnaround = $jobdoneu - $dateinu;
$ta = $turnaround / 86400;
$ta2 = round($ta, 2);
$adddays = $adddays + $ta2;
}
$avgturnaround = round($adddays / $howmany, 2);
echo("Average Turnaround Time (including weekends) = $avgturnaround Days");
This works perfectly, but if I could cancel out weekends I would get a much more accurate number for setting goals, etc...
Thanks for the help,
-Russell
$dateinu = strtotime("$datein");
$jobdoneu = strtotime("$jobdone");
$avgturnaround = 0;
for($i=$dateinu;$i<=$jobdoneu;$i+=86400)
{
$dayofweek = date("w",$i);
// if not Sunday and not Saturday increment $avgturnaround
if (($dayofweek!= 0) && ($dayofweek!= 6)) $avgturnaround++;
}
Check how this works carefully; there may be some "off by one" condition, but it should give you some ideas.