php - Form Options Date Picker - 1 Year -



php - Form Options Date Picker - 1 Year -

i have script lets me pick date dropdown list total year future, want same year past reversing not work.

here codes:

1 year ahead

<?php $day = date('y-m-d'); $last_day = date('y-m-d', strtotime($day . '+ 1 year')); while($day < $last_day) { echo '<option value="'.$day.'">'.date('js f y', strtotime($day)).'</option>'; $day = date('y-m-d', strtotime($day . ' + 1 day')); } ?>

1 year past

<?php $day = date('y-m-d'); $last_day = date('y-m-d', strtotime($day . '- 1 year')); while($day < $last_day) { echo '<option value="'.$day.'">'.date('js f y', strtotime($day)).'</option>'; $day = date('y-m-d', strtotime($day . ' - 1 day')); } ?>

the furure date picker works fine past picker doesn't show output. reason , what's teh solution?

what should alter change comparator in while loop's condition, i.e. next

while($day < $last_day) {

to

while($day > $last_day) {

reason

since $day today , $last_day date 1 year in past, ($day < $last_day) status never satisfy. within every loop, decrementing $day variable 1 day, starting today. so, need is, render alternative tag till $day variable greater $last_day variable.

php date drop-down-menu

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -