$month= $_POST['month'] or in different ways based on the version of PHP you are running. Here is the demo of the drop down list box for date format.
<?Php
$todo=$_POST['todo'];
if(isset($todo) and $todo=="submit"){
$month=$_POST['month'];
$dt=$_POST['dt'];
$year=$_POST['year'];
$date_value="$month/$dt/$year";
echo "mm/dd/yyyy format :$date_value<br>";
$date_value="$year-$month-$dt";
echo "YYYY-mm-dd format :$date_value<br>";
}
?>
<form method=post name=f1 action=''><input type=hidden name=todo value=submit>
<table border="0" cellspacing="0" >
<tr><td align=left >
<select name=month value=''>Select Month</option>
<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='04'>April</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>August</option>
<option value='09'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
</td><td align=left >
Date<select name=dt >
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
<option value='05'>05</option>
<option value='06'>06</option>
<option value='07'>07</option>
<option value='08'>08</option>
<option value='09'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
</td><td align=left >
Year(yyyy)<input type=text name=year size=4 value=2005>
<input type=submit value=Submit>
</table>
</form>
Strtotime returns unix timestamp by taking text string of date & time inputs
Here is the codefor($i=0;$i<=11;$i++){
$month=date('M',strtotime("first day of -$i month"));
echo $month ."<br>";
}
Output is here
Sep
Aug
Jul
Jun
May
Apr
Mar
Feb
Jan
Dec
Nov
Oct
Creating a dropdown list using above code
echo "<select name=month>";
for($i=0;$i<=11;$i++){
$month=date('F',strtotime("first day of -$i month"));
echo "<option value=$month>$month</option> ";
}
echo "</select>";
Output is here
Listing next 5 years starting from present year
echo "<select name=year>";
for($i=0;$i<=5;$i++){
$year=date('Y',strtotime("last day of +$i year"));
echo "<option name='$year'>$year</option>";
}
echo "</select>";
Output is here
Displaying calendar for selection of date by user
We can display calendar with browse button to navigate to different month and years.Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| vijayshankar | 07-08-2012 |
| This was the best post thank a lot dude | |
| muzika | 05-10-2013 |
| not good. there shouldn't be february 30 and 31 and 29 should only appear when it is leap year. | |
| smo | 06-10-2013 |
| Date validation is added in next section. Here it is demonstrated how to collect the date inputs. | |
| kossi | 14-02-2014 |
| great! But can you help me on how to do the validation for the month february | |
| ban | 16-07-2014 |
| simple , but have to take care about months having days less than 31. | |
| navneet | 07-11-2014 |
| i want only store day and month in database. please put regarding example... | |
| Yaz | 10-02-2019 |
| How to demonstrate the day less than 31? | |
| smo1234 | 11-02-2019 |
| Just remove the options . You can use the for loop with maximum limit of date you want. | |
20-02-2020 | |
| how do I send values to another php page | |