CoderZone.org

Category: >> PHP Code >> Month, Day, Year dropdown boxes Bookmark and Share

<< lastnext >>

Snippet Name: Month, Day, Year dropdown boxes

Description: Creates three SELECT form fields Month Day and Year.

Also see:
» Calculate days between any two dat...
» Easy date manipulation
» Convert UK Dates To mySQL Format D...
» Delete files older than 'X'
» String to Date
» Calculate date of Easter Sunday
» Define a schedule of holidays
» Calendar for any month any year
» Add and Subtract dates
» Basic PHP Calendar
» Convert 12 to 24 hour time and vic...
» What Season Is It?
» Delete by date
» Days in month #2
» Days in month #1
» Count days between dates
» Find days between dates #1
» Verify If Domain Really Exists
» Automatically Create Date Select B...

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?php 
 
    function DateSelector($inName, $useDate=0) 
    { 
        /* create array so we can name months */ 
        $monthName = array(1=> "January", "February", "March", 
            "April", "May", "June", "July", "August", 
            "September", "October", "November", "December"); 
 
        /* if date invalid or not supplied, use current time */ 
        if($useDate == 0) 
        { 
            $useDate = Time(); 
        } 
 
        /* make month selector */ 
        echo "<SELECT NAME=" . $inName . "Month>\n"; 
        for($currentMonth = 1; $currentMonth <= 12; $currentMonth++) 
        { 
            echo "<OPTION VALUE=\""; 
            echo intval($currentMonth); 
            echo "\""; 
            if(intval(date( "m", $useDate))==$currentMonth) 
            { 
                echo " SELECTED"; 
            } 
            echo ">" . $monthName[$currentMonth] . "\n"; 
        } 
        echo "</SELECT>"; 
 
        /* make day selector */ 
        echo "<SELECT NAME=" . $inName . "Day>\n"; 
        for($currentDay=1; $currentDay <= 31; $currentDay++) 
        { 
            echo "<OPTION VALUE=\"$currentDay\""; 
            if(intval(date( "d", $useDate))==$currentDay) 
            { 
                echo " SELECTED"; 
            } 
            echo ">$currentDay\n"; 
        } 
        echo "</SELECT>"; 
 
        /* make year selector */ 
        echo "<SELECT NAME=" . $inName . "Year>\n"; 
        $startYear = date( "Y", $useDate); 
        for($currentYear = $startYear - 5; $currentYear <= $startYear+5;$currentYear++) 
        { 
            echo "<OPTION VALUE=\"$currentYear\""; 
            if(date( "Y", $useDate)==$currentYear) 
            { 
                echo " SELECTED"; 
            } 
            echo ">$currentYear\n"; 
        } 
        echo "</SELECT>"; 
 
    } 
?> 
 
<HTML> 
<BODY> 
<FORM> 
Choose a Date: <?php DateSelector( "Sample"); ?> 
</FORM> 
</BODY> 
</HTML>
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 36