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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.