PHP / MySQL

  1. Home
  2. Computing & Technology
  3. PHP / MySQL

When is Columbus Day?

When is Columbus Day this year?

By Angela Bradley, About.com

In the United States we celebrate Columbus Day on the second Monday of October each year. While there is not a specific PHP function to generate what day this is (like Easter has) we can determine it using this script. Be sure to read the italic comments to better understand how the script is working!

<?php
//This gets today's date
$date =time () ;

//This makes the current year a variable
$year = date('Y', $date) ;

//Here we generate the first day of October
$first_day = mktime(0,0,0,10, 1, $year) ;

//We determine what day of the week the first falls on
$day_of_week = date('D', $first_day) ;

//Based upon this, we add the appropriate number of days to get to the second Tuesday of the month

switch($day_of_week){
case "Sun": $add = 8; break;
case "Mon": $add = 7; break;
case "Tue": $add = 13; break;
case "Wed": $add = 12; break;
case "Thu": $add = 11; break;
case "Fri": $add = 10; break;
case "Sat": $add = 9; break;
}

$Columbus = 1 + $add;

echo "This year, $year, Columbus day falls on 10/$Columbus.";
?>

This script uses the date () and time () functions to find the current year. You could also manually input a year if you prefered to find Columbus day for a different year. Once we determine what day the first of October falls on we can use a switch loop to add the appropriate amount of days to find the second Monday. Finally we echo () our result to our user.
More PHP / MySQL Quick Tips

Explore PHP / MySQL

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

PHP / MySQL

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Step By Steps
  5. PHP and Columbus Day - Use PHP to Determine when Columbus Day is

©2009 About.com, a part of The New York Times Company.

All rights reserved.