My collection of things.

jKafer on the Net

January 21st, 2014 at 10:40 am

A bit of php programming…

I do this type of programming about 4 times a year and each time I have to lookup how to compare dates in php. There are so many options and some make it out to be so complicated I thought I would just thru my answer into the pool. The following code is used to display a message depending on the date. Basically it announces a business will be closed for a holiday.

I use a multidimensional array to hold the holiday information, then go thru it to see if it needs to be displayed. This is also setup so that more than one message could appear at any given time (usually around Christmas & New Years). As you can see from my array, I supplied 2 dates – start date and end date.

array definition: collection = array(start date, end date, first line of message, second line of message)

php code :


$holidays = array(
“Easter”=>array(‘2013-03-20′,’2013-03-30′,’Friday March 29th’,’in recognition of Good Friday’),
“MemDay”=>array(‘2013-05-15′,’2013-05-28′,’Monday May 27th’,’in recognition of Memorial Day’),
“IndDay”=>array(‘2013-06-25′,’2013-07-05′,’Thursday July 4th’,’in recognition of the 4th of July’),
“LabDay”=>array(‘2013-08-15′,’2013-09-03′,’Monday September 2nd’,’in recognition of Labor Day’),
“Christmas”=>array(‘2013-12-10′,’2013-12-26′,’Tues December 24th & Wed, December 25th’,’in recognition of Christmas’),
“NewYear”=>array(‘2013-12-12′,’2014-01-02′,’Wed January 1st’,’in recognition of New Years Day’)

$txtMsg = ‘<p>We will be closed<br /> ‘;
$MsgCount = 0;
$today = date(“Y-m-d”);
foreach ($holidays as $value)

if (date($value[0])<$today && date($value[1])>$today)
$txtMsg .= ‘* <span>’.$value[2].'</span> * <br />’;
$txtMsg .= $value[3].'</p>’;

if ($msgCount >0) {
print $txtMsg;


I could have had the php code write out the day of the week, Month name etc, but because of limited space where this is being placed on the web page, I wanted to control what was displayed. For example, where Christmas is 2 days, writing out the complete names of the days would have caused it to wrap around and look out of place on the web page. But you sure could do that if you wanted to.

I actually have an excel worksheet that has this data in it and does the calculations for me to set the start date 10 days ahead of the shutdown date.


Comments are closed.

  • Count per Day

    • 4Visitors today:
    • 40Visitors per day:
    • 0Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • Blue Carolina Starburst Quilt {Free Pattern}

    • Well Texas Tumbleweeds got finished.  If you missed that, find it here.  So it’s time for a new UFO.  Earlier I had pulled Fair and Square but after I got the string triangles done, I left it…

    • 719 Likes, 25 Comments - David (@scfdavid) on Instagram: “Here’s my Blockheads block for Week 45 - Double Dutch - from my friend, Jo Morton! Thanks, Jo! All…”

    • Quilt patriotic Hidden Glorry reserved for Carrie by marytequilts

    • Tutorial - How to Get Perfect Centers

    • How to sew and trim half rectangle triangles (HRTs) - Kirsty of Bonjour Quilts

    • Center Point designed by Elise Lea for Robert Kaufman. Features Chalk and Charcoal by Jennifer Sampou, shipping to stores May 2018. Roll up friendly. FREE pattern available for download from May 2018. #FREEatrobertkaufmandotcom

    • A modern quilt blog focused on practical tutorials and quilting tips. Sharing traditionally pieced quilt patterns and lots of free quilt alongs.