annual leave calclation

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 11
Joined: Fri Jul 25, 2003 11:52 pm

Sat Jul 26, 2003 4:41 am


is it possible to write a php code about the leave for a staff?
like the usaul ompany, after two years work a staff will get the bonus leave 1 day in third year........and fourth years have 2 days bonus leave........

thank you.......

User avatar
Joan Garnet
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Sat Jul 26, 2003 2:18 pm

You can do it by keeping dates in a database and then calculate the bonus.
Do you have any code yet?
If not we can try to do it from scratch.

New php-forum User
New php-forum User
Posts: 11
Joined: Fri Jul 25, 2003 11:52 pm

Sun Jul 27, 2003 10:02 am

this is my code without counting the years.....
if i add a empty fields to give the staff fill in when they r join this company in a year format.e.g 1999.
then how can i add this function into this coding and also this is where im very clear about it.
can u do a correction to me pls?

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";
$entitlement = 18;
$leave_to_date = 0;

**** is it here am i going to start?***********

$balance = $entitlement - $leave_to_date - $Duration;

echo $Duration ;


Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 10 guests