Get all work days in a year

Hi experts,

I need to make a record in my MySQL database for every work day in a year. Hollydays are not important in this script as long as it does not include sundays or saterdays.

I found this script (see below) but it does not work.

(script found : http://www.bitsntricks.com/php-script-how-to-find-the-working-days-from-a-specified-date/)

It gives me an error;

Parse error: syntax error, unexpected T_STRING in \workdays.php on line 39

Can someone please help me acceive my goal?

Thanks

<?php

echo workingDays( "05-01-2011", "10");

/*

This is a function to find out working days from a specified date and  format of date must be dd-mm-yyyy

First parameter to function is the date from which working days are to be calculated (working day exclude Sun and Sat)

Second parameter to function is the number of working days to be calculated

*/

function workingDays( $fromDate, $interval )  {

$date_array = explode(‘-’, $fromDate );

$day                      = $date_array[0];

$month                                = $date_array[1];

$year                     = $date_array[2];

$working_date = array();

for ( $i = 1;  $i <= $interval; $i++ )               {

$day_text = date(“D”, mktime( 0, 0, 0,$month,$day + (int)$i,$year));

if( $day_text == ‘Sat’ || $day_text == ‘Sun’ )  {

$interval++;

continue;

}

$working_date[] = date(“F j, Y”, mktime(0, 0, 0,$month,$day +(int)$i,$year));

}

return $working_date;

}

$getWorkingDays = workingDays(’19-05-2010', 10 );

echo “<pre>————————–Array with all working days ————————————–<br/>”;

print_r($getWorkingDays);

echo “——————————- Last working day—————————————————<br/>”;

echo $getWorkingDays[count($getWorkingDays)-1];

?>

Open in new window

LVL 1
SteynskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rik-LeggerCommented:
Try this on line 39:

$working_date[] = date('F j, Y', mktime(0, 0, 0,$month,$day +(int)$i,$year));

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Beverley PortlockCommented:
Try this code....

<?php


     function getWorkingDays( $y ) {

          $arr = array();

          $testDate = "$y-01-01";

          for( $i=0; $i < 366; $i++ ) {

               // See if we are in next year
               //
               if ( date("Y", strtotime($testDate) ) != $y )
                    break;

               // Check what the day is. If not a weekend then
               // put in the results array
               //
               $day = date("D", strtotime($testDate) );
               if ( $day != "Sat" && $day != "Sun" )
                    $arr [] = $testDate;
               

               // Advance to the next day
               //
               $testDate = date("Y-m-d", strtotime("$testDate +1 day") );
          }


          return $arr;
     }



$year = 2011;
print_r( getWorkingDays( $year ) );

Open in new window

0
SteynskAuthor Commented:
Thanks..
All quotes were wrong....
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.