Here is the code rewritten a bit. I would probably use CGI to generate the drop down, but this should give you an idea. I use $x as the offset and loop over it unshift (push but on the other end of the array so i don't have to reverse). This way you can do 0-45 and get exactly what you want. BTW This code does 45 days (excluding weekends), not the last 45 work days.
#!/perl/bin/perl
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Date::Calc qw(Add_Delta_Days Day_of_Week);
use strict;
# DATE DROPDOWN (last 30 business days) common wherever found
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon++;
$year += 1900;
my (@date_dd_from,@date_dd_to);
#Sample dates
my $selected_date_from = "1/23/2008";
my $selected_date_to = "1/23/2008";
for my $x (0..45) { # 45 days later
my ($n_year,$n_mon,$n_mday) = Add_Delta_Days($year,$mon,$mday,$x)
+;
if (Day_of_Week($n_year,$n_mon,$n_mday) < 6) {
my $date = "$n_mon/$n_mday/$n_year";
my $from_selected = $date eq $selected_date_from ? 'selected'
+ : '';
my $to_selected = $date eq $selected_date_to ? 'selected'
+ : '';
unshift @date_dd_from, "<option $from_selected value='$date'>$dat
+e</option>\n";
unshift @date_dd_to, "<option $to_selected value='$date'>
+$date</option>\n";
}
}
print "\n", @date_dd_to, "\n";
|