?
Solved

Php Date Omit Bank Holidays

Posted on 2016-11-01
3
Medium Priority
?
44 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 111

Expert Comment

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

All the best, ~Ray
0

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
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 count occurrences of each item in an array.
Suggested Courses

800 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