Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Month, Day, Year dropdown boxes Jump to:  
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:
» Convert UK Dates To mySQL Format Dates
» 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 vice ve...
» What Season Is It?
» Delete by date
» Days in month #2
» Days in month #1
» Count days between dates
» Find days between dates #1
» Build Date Select Boxes

Comment: (none)

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>
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 65 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?