#native_company# #native_desc#
#native_cta#

Workdays Elapsed for Current Month

By Rickey Johnson
on July 25, 2002

Version: 0.1

Type: Sample Code (HOWTO)

Category: Calendars/Dates

License: GNU General Public License

Description: This can basically be used as an include file. It calculates the number of workdays that have elapsed in the given month. Holidays are editable and excluded.

<?
//DO NOT CHANGE ANYTHING IN THIS SECTION
//Not the most beautiful code... but it should be pretty straight foward
//Send comments, questions or suggestions to [email protected]

//get todays date
$today=date(Y-m-d);

//day of current month
$daynum=date(d);

//grab the day of the week and set workday =1 if it is a weekday
$dayofweek=date(l);
if ($dayofweek=="Monday"){$workday=1;}
elseif ($dayofweek=="Tuesday"){$workday=1;}
elseif ($dayofweek=="Wednesday"){$workday=1;}
elseif ($dayofweek=="Thursday"){$workday=1;}
elseif ($dayofweek=="Friday"){$workday=1;}
else {$workday=0;}

//while loop to add/subtract workdays
while ($daynum != 01)
{
$month=date(m);
$year=date(Y);
$daynum=$daynum-01;

$past="$year-$month-$daynum";
$pasttime=mktime(0,0,0,$month,$daynum,$year);
$pastdayofweek=date(l,$pasttime);
if ($pastdayofweek=="Monday"){$workday=$workday+1;}
if ($pastdayofweek=="Tuesday"){$workday=$workday+1;}
if ($pastdayofweek=="Wednesday"){$workday=$workday+1;}
if ($pastdayofweek=="Thursday"){$workday=$workday+1;}
if ($pastdayofweek=="Friday"){$workday=$workday+1;}
//END OF FIRST UNEDITABLE SECTION


//THIS SECTION CONTAINS THE HOLIDAYS AND IS WHAT WILL NEED EDITING ONCE A YEAR IF
//YOUR HOLIDAYS CHANGE
$newyear="2002-01-1";
$memorialday="2002-05-27";
$independenceday="2002-07-4";
$laborday="2002-09-2";
$thanksgiving="2002-11-28";
$thanksgiving2="2002-11-29";
$xmas1="2002-12-25";
$xmas2="2002-12-26";
$xmas3="2002-12-27";
//THIS IS THE END OF THE HOLIDAYS SECTION


//If you add extra holidays you will need to put it in here as well
if ($past==$newyear){$workday=$workday-1;}
if ($past==$memorialday){$workday=$workday-1;}
if ($past==$independenceday){$workday=$workday-1;}
if ($past==$laborday){$workday=$workday-1;}
if ($past==$thanksgiving){$workday=$workday-1;}
if ($past==$thanksgiving2){$workday=$workday-1;}
if ($past==$xmas1){$workday=$workday-1;}
if ($past==$xmas2){$workday=$workday-1;}
if ($past==$xmas3){$workday=$workday-1;}
//prints each day
print("$past     $pastdayofweek<br>");
}

//prints the elapsed workdays
print("Elapsed workdays:  $workday");

//Thats it... hope this is useful
?>