How can I add a Month dropdown in my HTML form using the PHP function? I have tried with this code.
<select class="form-control" name="select_month"> <?php for ($i = 0; $i <= 12; ++$i) { $time = strtotime(sprintf('-%d months', $i)); $Monthdecimalvalue = date('m', $time); $MonthName = date('F', $time); printf('<option value="%s">%s</option>', $Monthdecimalvalue, $MonthName); } ?> </select>
This code does not work for me properly, it does not list January to December, it listed the month’s name current name to the end of the month. But I need to display month name serialize like January to December. How can I do it?
To add January to December month drop down in HTML using PHP, apply this code.
<select name="select_month" class="form-control"> <option value=""> -- Choose -- </option> <?php for ($i = 1; $i <= 12; ++$i) { echo '<option value="'. date('F', mktime(0,0,0,$i)).'">'. date('F', mktime(0,0,0,$i)).'</option>'."\n"; } ?> </select>
Question and answer is powered by AnsPress.io