Solved

Php Date Omit Bank Holidays

Posted on 2016-11-01
3
6 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
  • 2
3 Comments
 
LVL 108

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 108

Expert Comment

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

All the best, ~Ray
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now