Peter Mackenzie's Time Example

Month:
Day:
Day Name:


Select a Month, day and day of the week, and this script will tell you the next 5 years that date will be that day of the week.

 

CODE FOLLOWS

<?php
    
include('includes/header.php');// code

    
error_reporting(E_ALL);    // set error reporting to all
    
date_default_timezone_set("America/Detroit");//set timezone
    
$self basename($_SERVER['SCRIPT_NAME']);

    
$month = isset($_POST['month']) ? $_POST['month'] : null;
    
$day = isset($_POST['day']) ? $_POST['day'] : null;
    
$dayname = isset($_POST['dayname']) ? $_POST['dayname'] : null;
    
$montharray = array ("filler","January","February","March","April","May","June","July","August","September","October","November","December");
    
$step = isset($_POST['step']) ? $_POST['step'] : null;

    
//echo("month is $month<br>");
    //echo("day is $day<br>");
    //echo("day name is $dayname<br>");
    //$d=cal_days_in_month(CAL_GREGORIAN,2,2005);
    //echo "There was $d days in October 2005<br>";

    //form
    
if ($step == 1)
        {
        
$validdate true;
        
//check for max day error
        
if ($day 28)//we can only have errors for days 29-31
            
{
            
$d=cal_days_in_month(CAL_GREGORIAN,$month,2000);//lets just give a leap year
            //echo("days in month is $d<br>");
            
if ($day $d)
                {
                
$validdate false;
                echo(
"<h1>Sorry, $montharray[$month] only has $d days, not $day. </h1>");
                }
            }
        if (
$validdate)
            {
            
//ok, we have a valid date, we might also have feb 29, will worry about that in a min
            
$seconds strtotime("now");    //
            
$date getdate($seconds);//get today, right now.
            
$year $date['year'];//we now have the current year.
            //echo ("year is $year<br>");
            
$counter 0;
            echo(
"<h1>Next 5 years (Not including this one) where $montharray[$month] $day is a $dayname. </h1>");
            while (
$counter 5)
                {
                
$year++;//increment year
                
if ($month == && $day == 29)//check for feb 29th being selected
                    
{
                    
$validdate true;//reset $validdate just in case
                    
$d=cal_days_in_month(CAL_GREGORIAN,2,$year);//lets see if this is a leap year
                    
if ($d != 29)
                        {
                        
$validdate false;
                        }
                    }

                if (
$validdate)
                    {
                    
$seconds strtotime("$montharray[$month] $day $year");    //
                    
$date getdate($seconds);//get details of that day in a future year
                    //$temp = $date['weekday'];
                    //echo ("$montharray[$month] $temp $dayname $year <br>");

                    
if ($date['weekday'] == $dayname)
                        {
                        
//we have a match, that date is that day of the week
                        
echo("<p><b>$year</b></p>");
                        
$counter++;//increment counter
                        
}
                    }


                }
            }

        
?>


            <form action="<?php echo($self); ?>" method="POST">
                <p>
                    <input type="hidden" name="step" value="0">
                    <input type="submit" name="submit" value="Try Again">
                </p>
            </form>
            <?php

        
}
    else {
    
?>

        <h1>Peter Mackenzie's Time Example</h1>

        <form action="<?php echo($self); ?>" method="POST">
            <table style="width:50%">
                <tr>
                    <td class="right">
                        Month:
                    </td>
                    <td class="left">
                        <select name="month">
                            <?php
                                
for ($x 1$x 13$x++) {
                                echo(
"<option value=\"$x\">$montharray[$x]</option>");
                                }
                            
?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="right">
                        Day:
                    </td>
                    <td class="left">
                        <select name="day">
                            <?php
                                
For ($x 1$x 32$x++) {
                                echo(
"<option value=\"$x\">$x</option>");
                                }
                            
?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="right">
                        Day Name:
                    </td>
                    <td class="left">
                        <select name="dayname">
                            <option value="Sunday">Sunday</option>
                            <option value="Monday">Monday</option>
                            <option value="Tuesday">Tuesday</option>
                            <option value="Wednesday">Wednesday</option>
                            <option value="Thursday">Thursday</option>
                            <option value="Friday">Friday</option>
                            <option value="Saturday">Saturday</option>
                        </select>
                    </td>
                </tr>
            </table>
            <p>
                <input type="hidden" name="step" value="1"> <br>
                <input type="submit" name="submit" value="Submit">
            </p>
        </form>

        <p>
            Select a Month, day and day of the week, and this script will tell you the next 5 years that date will be that
            day of the week.
        </p>
        <?php
    
}

    include(
'includes/footer.php');// code
?>