Jump to content

Date Select Menu


ShoeLace1291

Recommended Posts

I need a select dropdown menu that lists the name and number of the current month, the next month, and the previous month.  It would have to look something like this:

 

<select name='month'>

<option value='1'>January</option>

<option selected value='12'>December</option>

<option value='11'>November</option>

</select>

 

This would change every month.  For example, next month, January, would list February as the first month, January as the selected month, and December as the previous month.  I have no idea how I would do something like this.

Link to comment
https://forums.phpfreaks.com/topic/80164-date-select-menu/
Share on other sites

<?php
echo '<select name="month">
';
for ( $x = -1 ; $x < 2 ; $x++ ) {
    $selected[0] = ' selected';
    $month = get_month($x);
    echo '    <option value="' . $month[0] . '"' . $selected[$x] . '>' . $month[1] . '</option>
';
}
echo '</select>';

function get_month($offset) {
    return explode(" ", date("n F", mktime( 0, 0, 0, date("n")+$offset, 1, date("Y") )) );

}

?>

/* HTML Source

<select name="month">
    <option value="11">November</option>
    <option value="12" selected>December</option>
    <option value="1">January</option>
</select>
*/

 

PhREEEk

Link to comment
https://forums.phpfreaks.com/topic/80164-date-select-menu/#findComment-406318
Share on other sites

This will set the time using mktime(); and then print the time;

if($_POST['submit']) {
$month = $month = date("M", mktime(0,0,0,$_POST['month'],0,0,0));
print 'Month is: ' . $month;
}
else {		
print '<form action=' . $_SERVER['PHP_SELF'] . ' method=post>';	
print '<select name=month>';
print '<option value=1>January</option>';
print '<option value=2>Febuary</option>';
print '<option value=3>March</option>';
print '<option value=4>April</option>';
print '<option value=5>May</option>';
print '<option value=6>June</option>';
print '<option value=7>July</option>';
print '<option value=8>August</option>';
print '<option value=9>September</option>';
print '<option value=10>October</option>';
print '<option value=11>November</option>';
print '<option value=12>December</option>';
print '</select>';
print '<input type=submit name=submit value=Submit />';
print '</form>';
}

Link to comment
https://forums.phpfreaks.com/topic/80164-date-select-menu/#findComment-406329
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.