Version: 1.0

Type: Function

Category: Calendars/Dates

License: GNU General Public License

Description: I was looking for the easiest, quickest way to add a date picker to my internal web site without having to add more javascript or a pop-up window. I found several fantastic javascripts to add calendars to the page and a few even used layers instead of pop-ups, but I was looking for something simpler. I noticed that although the javascript calendars will allow you to pick a date years away, most of my users were picking dates in the next 60 days and no more than 120 ever. So for my application I came up with this. Quick and easy you just call the function whereever you want the date dropdown to show up. You can force the name of the <select> field with the $default param and you can specify the number of days to display with the $size param. http://www.multi.com/Coding/PHPDateDropDown.php



function DateDropDown($size=90,$default="DropDate") {
   // $size = the number of days to display in the drop down
   // $default = Todays date in m:d:Y format (SEE DATE COMMAND ON WWW.PHP.NET)
   // $skip = if set then the program will skip Sundays and Saturdays
   $skip=1;
   echo "<select name=dropdate STYLE=\"font-family: monospace;\">\n";
   for ($i = 0; $i <= $size; $i++) {
      $theday = mktime (0,0,0,date("m") ,date("d")+$i ,date("Y"));
      $option=date("D M j, Y",$theday);
      $value=date("m:d:Y",$theday);
      $dow=date("D",$theday);
      if ($dow=="Sun") {
         echo "<option disabled>&nbsp;</option>\n";
      }
      if ($value == $default) {
         $selected="SELECTED";
      } else {
         $selected="";
      }
      if (($dow!="Sun" and $dow!="Sat") or !$skip) {
         echo "<option value=\"$value\" $selected>$option</option>\n";
      }
   }
   echo "</select>\n";
}