datetime - PHP get years and month to a select box -


i'm writing codes show years , months of past years

ex

<select>                                             <option value="03/2014">03/2014</option>                                             <option value="02/2014">02/2014</option>                                             <option value="01/2014">01/2014</option>                                             <option value="12/2013">12/2013</option>                                             <option value="11/2013">11/2013</option>                                             <option value="10/2013">10/2013</option>  </select> 

im using code can moonth names

 $i = 1; $month = time(); while($i <= 12) {     $month_name = date('f', $month);     echo '<option value="'. $month_name. '">'.$month_name.'</option>';     $month = strtotime('+1 month', $month);     $i++; } 

but need month , year past 4,5 years, know how using php date function or other short way.thank you

put function:

$start = strtotime('2014-01'); $end = strtotime('2014-12'); $range = array(date('y-m', $start) => date('y-m', $start)); while ( $start <= strtotime('-1 month', $end) ) {     $start = strtotime('+1 month', $start);     $yearmonth = date('y-m', $start);     $range[$yearmonth] = $yearmonth; } var_dump($range); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -