Jump to content

Excluding Weekends in a dropdown box of dates


ShopMAster

Recommended Posts

Hello Coders,

 

  I'm having some trouble with this and maybe you can help me out.  I'm displaying the last 15 days in a dropdown list but I can't figure out how to exclude the weekends (Sat and Sun) from that list.  I'm kind of new to this whole PHP stuff so any help would be very much appreciated:

 

  Here is what I have

 

 

<form name="form" id="form">
       <select name="jumpMenu" id="jumpMenu">
       <option value="#">Select Day</option>
       <?php 
   $m= date("m");
       $de= date("d");
       $y= date("Y");
        for($i=0; $i<=15; $i++){
        echo "<option value=daytest.php?dateselect=" . date('mdy',mktime(0,0,0,$m,($de-$i),$y)) . "&day=" . date('F d, Y',mktime(0,0,0,$m,($de-$i),$y)) . "'>" . date('D, F d, Y',mktime(0,0,0,$m,($de-$i),$y)) . "</option>";

} 
?>
       </select>
       <input type="button" name="go_button" id= "go_button" value="Go" onclick="MM_jumpMenuGo('jumpMenu','parent',0)" />
     </form>

 

Thanks for your guidance.

Link to comment
Share on other sites

prolly easier to do in a while for this:

$i = 0;
$num_days = 0;
while( $num_days < 15 ){
        if(date('D',mktime(0,0,0,$m,($de-$i),$y)) != "Sat" && date('D',mktime(0,0,0,$m,($de-$i),$y)) != "Sun"){
echo "<option value=daytest.php?dateselect=" . date('mdy',mktime(0,0,0,$m,($de-$i),$y)) . "&day=" . date('F d, Y',mktime(0,0,0,$m,($de-$i),$y)) . "'>" . date('D, F d, Y',mktime(0,0,0,$m,($de-$i),$y)) . "</option>";
$num_days++;
}

$i++;
}

something like that.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.