Solved

Php Date Omit Bank Holidays

Posted on 2016-11-01
3
36 Views
Last Modified: 2016-11-01
Hi,

I have this code to search for working days during a date range.

function getWorkingDays($startDate, $endDate) {

        $businessDays = array();
        $businessDaysInWeek = range(1,5);      // Only Monday to Friday

        // Decompose the provided dates.        
        list($startYear, $startMonth, $startDay) = explode('-', $startDate);
        list($endYear, $endMonth, $endDay) = explode('-', $endDate);

        // Create our start and end timestamps.
        $startStamp = mktime(1, 1, 1, $startMonth, $startDay, $startYear);
        $endStamp = mktime(1, 1, 1, $endMonth, $endDay, $endYear);

        // Check each day in turn.
        for($loop=$startStamp; $loop<=$endStamp; $loop+=86400) {
            if(in_array(date('N', $loop), $businessDaysInWeek)) {

                // You'll also want to omit bank holidays, etc. in here.

                $businessDays[] = date('Y-m-d', $loop);
            }
        }

        return $businessDays;
    }
	
	$month = getWorkingDays('2016-11-01','2016-11-30');

Open in new window


It has the section

// You'll also want to omit bank holidays, etc. in here.

Open in new window


I'm lost as to how I add the bank holiday dates into this section, please help.

Thanks Simon
0
Comment
Question by:pc-buddy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 41868494
This is a well-understood design pattern.  Your weekend days both start with "S" so it's easy to remove them from the collection.  For the other, date-specific holidays, you add them separately according to the rules that determine the holiday.  For example, Christmas is always December 25, USA Thanksgiving is the fourth Thursday in November, etc.  These rules are easy to implement.  Please see Practical Application #9 in this article:
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html
0
 

Author Closing Comment

by:pc-buddy
ID: 41868722
Brilliant thanks
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41868753
Thanks for the points -- it's a great question!

All the best, ~Ray
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

731 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question