How can I put this array into a select menu, It is sort of a mini date picker

$d= substr($start,8,2); // last 2 digits = Day
$m= substr($start,5,2); // 2 middle digits = Month
$y= substr($start,0,4); // first 4 digits = Year

$test=array(); // Declare ARRAY

for($i=0; $i<=$totaldays; $i++){
$test[$i]=date(‘D, M-d’,mktime(0,0,0,$m,($d+$i),$y)); // Increases day until it gets to totaldays
// echo $test[$i].“<br/>”;

<pre><?php print_r($test); ?></pre>

<form id=“form1” name=“form1” method=“post” action=“”>
Start Date: <input type = “date” name = “doj” /><br />
<input type = “submit” value = “Submit” />

Is this what you want?


$start      = '2011-12-05';
$end        = '2011-12-16';
$totaldays  = ((date(strtotime($end)) - date(strtotime($start))) / 86400);

$d = substr($start, 8, 2); // last 2 digits    = Day
$m = substr($start, 5, 2); // 2 middle digits  = Month
$y = substr($start, 0, 4); // first 4 digits   = Year


<form id="form1" name="form1" method="post" action="">
    Start Date: <input type="date" name="doj" /><br />
    <select name="date">
    for ($i = 0; $i <= $totaldays; $i++) {
        $date = date('D, M-d', mktime(0, 0, 0, $m, ($d+$i), $y));
        echo '<option value="' . $date . '">' . $date . '</option>';
    <input type="submit" value="Submit" />

It helps a lot, thanks, I’ll work on it a little more

$start = "2011-11-30";
$end = "2011-12-25";

$sql_next = date("Y-m-d", strtotime($start . "- 1 day"));

while( $sql_next !== $end){
$next = strtotime($sql_next . ' + 1 day');
$sql_next = date('Y-m-d', $next) ;
$nice_next = date('D, M-d', $next) ;
echo "<option value=$sql_next>$nice_next</option>" . PHP_EOL;

//<option value=2011-11-30>Wed, Nov-30</option>
//<option value=2011-12-01>Thu, Dec-01</option>
//<option value=2011-12-02>Fri, Dec-02</option>
//<option value=2011-12-03>Sat, Dec-03</option>
//<option value=2011-12-04>Sun, Dec-04</option>
// and so on ...

Here’s another way, I imagined you’d really want a 2011-12-25 style date passed back to your form handler, if you did not then it can be one line less. :slight_smile:

I’m making a time sheet for where I work.
I’m learning as I go along. The employees will log in and enter their daily hours.
Any help is appreciated, thanks
The start and end date will come from the database and limit them to enter only those dates of the pay period.
the start date and end will be a pull down menu
the start and end time, havn’t figured that out yet, there is too much to have a pull down in 15 min blocks
lunch and break times

So are you saying they don’t enter their times each day as the work period progresses, but have to enter them at, say, the end of the week?

Sorry i left for work.
Ya, they enter it the same day or next day. They put the time they started and the time they finished with the date started and an extended date if the shift carried over to the next day, like a night shift.