#!usr\bin\perl use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use DBI; use Date::Calc qw(Add_Delta_Days Day_of_Week); print header(); # *********************************************************GET DATE my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); $mon++; $year += 1900; #Let me calculate the date range, now to 45 business days later::: my (@n_date, $date_from, $date_to); 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_year-$n_mon-$n_mday"; push @n_date, $date; } }# end my for... $date_from = $n_date[0]; $date_to = $n_date[-1]; my $dbh = DBI->connect("DBI:ODBC:myserver",$user, $pass) || print "Connect fail: $!"; my $sql="SELECT ACCOUNT,SDATE, AMOUNT FROM MAINTABLE WHERE ACCOUNT<> 0 AND SDATE BETWEEN '$date_from' AND '$date_to'"; #45 days my $sth = $dbh->prepare($sql); $sth->execute() || die $sth->errstr;