Dates in a select box.. mktime() ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Dates in a select box.. mktime() ?

Post 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!
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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>';
?>
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

yepp jam it works well and you saved 10 mins to write it down thanks..

what a luck! :lol:
Post Reply