<?php
function count_workdays($date1,$date2){
$firstdate = strtotime($date1);
$lastdate = strtotime($date2);
$firstday = date(w,$firstdate);
$lastday = date(w,$lastdate);
$totaldays = intval(($lastdate-$firstdate)/86400)+1;
//check for one week only
if ($totaldays<=7 && $firstday<=$lastday){
$workdays = $lastday-$firstday+1;
//check for weekend
if ($firstday==0){
$workdays = $workdays-1;
}
if ($lastday==6){
$workdays = $workdays-1;
}
}else { //more than one week
//workdays of first week
if ($firstday==0){
//so we don't count weekend
$firstweek = 5;
}else {
$firstweek = 6-$firstday;
}
$totalfw = 7-$firstday;
//workdays of last week
if ($lastday==6){
//so we don't count sat, sun=0 so it won't be counted anyway
$lastweek = 5;
}else {
$lastweek = $lastday;
}
$totallw = $lastday+1;
//check for any mid-weeks
if (($totalfw+$totallw)>=$totaldays){
$midweeks = 0;
} else { //count midweeks
$midweeks = (($totaldays-$totalfw-$totallw)/7)*5;
}
//total num of workdays
$workdays = $firstweek+$midweeks+$lastweek;
}
/
check for and subtract and holidays etc. here
...
/
return ($workdays);
} //end funtion count_workdays()
$date1 = "$FromDate";
$date2 = "$ToDate";
echo $Duration ;
?>
work days </td>
</tr>
<tr>
<td width="23%" height="24"> </td>
<td width="33%" height="24">Reason :</td>
<td width="44%" height="24">
<? echo $Reason ?>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="23%" height="26"></td>
<td width="33%" height="26">Balance :</td>
<td width="44%" height="26">
<?php
function count_balance($entitlement,$duration1)
$entitlement = 18;
$duration1 = $duration;
$balance = $entitlement - $duration1;
echo $balance;
?>
days </td>
the entitlement was fixed already = 18 days...
now i want to count the balance of leave in another fields.