Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Php Date Omit Bank Holidays

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 dynamically set the form action using jQuery.
Suggested Courses

610 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