Calculating U.S. Federal Holidays with PHP

A while ago, I had written a PHP class that would calculate all the U.S. Federal Holidays for a given year. I recently had a chance to take a second look at the code and discovered a few cases where the dates returned by my function weren’t matching the holidays provided by the U.S. Office of Personnel Management. In particular, I had failed to account for those fixed holidays (e.g. Independence Day, on July 4) that fall on a Saturday or Sunday: in those cases, the preceding Friday or following Monday, respectively, will be considered a Federal Holiday. As far as I can tell, the Federal Holidays haven’t changed since 1968, but the U.S. Office of Personnel Management’s web site doesn’t provide a calendar prior to 1997, so I decided to put the same limitation in my code:

If the class is instantiated without any parameter, the current year will be implied; if a year is passed to the constructor, it will be checked whether it is an integer great than 1996 (and throw an exception if not). The class has only one public method, get_list(), which will return an array of holidays: each holiday is represented as an associative array containing two elements, name (e.g., Christmas) and timestamp. The following example will show a table with the US Federal Holidays for the current year:

The result for 2013 should be like this:

New Year’s Day January 1, 2013
Birthday of Martin Luther King, Jr. January 21, 2013
Wasthington’s Birthday February 18, 2013
Memorial Day May 27, 2013
Independence day July 4, 2013
Labor Day September 2, 2013
Columbus Day October 14, 2013
Veteran’s Day November 11, 2013
Thanksgiving Day November 28, 2013
Christmas December 25, 2013
Today (November 17, 2013) is not a holiday.


  1. Marion Dorsett February 16, 2017 at 10:07 pm

    I found your class, and it was very useful, however, it changes the date_default_timezone_set() for the application which is not good.

    I rewrote the __construct()or method, to use the PHP DateTime and DateTimezone classes instead.

    If you’re interested I can email the revised code to you, or if you have it on GitHub, I can update it there and you can merge the changes.

    1. Pete November 15, 2017 at 2:16 pm

      I am interested. Can you put it on GitHub?

    2. Trace Gamillion February 8, 2018 at 2:06 pm

      Can I please have your updated code?

    3. Carl Monie March 29, 2018 at 2:51 am

      I am interested in the revised code that does not change the default timezone

  2. Aaron Dinin February 18, 2017 at 7:48 pm

    This was a fantastic bit of code. Since nobody else has commented on it, I figured I would just to say “thank you!”

  3. Edward Melville October 9, 2017 at 4:54 pm

    Bummer, didn’t work for today (Columbus Day)

  4. Goose November 10, 2017 at 1:49 pm

    This years thanksgiving results in false


  5. Trace Gamillion February 8, 2018 at 2:14 pm

    Can I please have your updated code?

  6. Macarthurval March 1, 2018 at 10:41 pm

    Same than above, thanks man!, I have adapted it for mexican holidays.

  7. Carl Monie March 29, 2018 at 2:52 am

    I am interested in the revised code that does not change the default timezone

  8. Greg Baughman August 20, 2018 at 4:18 pm

    I’m a little confused on why you have “New Years Day” and say “January 1st, if not a Saturday or Sunday”…

    Maybe I’m not understanding the code, but the day of the week doesn’t change if it’s new years’… or is that calculating for the nearest day (in case, say, New Years is on a Sunday, so employees give Monday off?)

  9. Rich C November 26, 2018 at 4:50 pm

    Thanks for this class! I used it to create a version more appropriate for our needs. It has a few improvements over the original – one of which is that it doesn’t have the same timezone issue as the original.

    If anyone is interested, feel free to use it:

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.