Page 1 of 1

Dates in a select box.. mktime() ?

Posted: Sun Apr 18, 2004 12:55 am
by Steveo31
Hey all-

I'd like to make a drop-down box with the values of the next 30 (or so) days, no matter the day or the month. For example, today is April 17, and I would like it to have the values April 18 to May 20 (or whatever it may be).

Getting the dates is the problem. After that I can throw them into a drop-down box no prob. I'm think mktime() would be help here, but I'm unsure of how to implement it in this case.

Thanks!

Posted: Sun Apr 18, 2004 2:41 am
by JAM
Perhaps something like... (Untested, should work after some tweaking).

Code: Select all

<?php
    $arr = getdate(time());
    echo '<select name="date">';
    echo '<option>'.date("M-d-Y", mktime(0, 0, 0, $arr['mon'], $arr['mday'], $arr['year'])).'</option>';
    for($i=0;$i<=30;$i++) {
        echo '<option>'.date("M-d-Y", mktime(0, 0, 0, $arr['mon'], $arr['mday']+$i, $arr['year'])).'</option>';
    }
    echo '</select>';
?>

Posted: Sun Apr 18, 2004 6:30 am
by mudkicker
yepp jam it works well and you saved 10 mins to write it down thanks..

what a luck! :lol: