没必要用循环判断吧,简化一下:
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,k,l:Integer;
wDays:Integer;
sDate:TDate;
begin
i:=Abs(Trunc(DateTimePicker1.Date)-Trunc(DateTimePicker2.Date));//两日期间隔总天数
sDate := DateTimePicker1.Date;
j:= i div 7;//两日期间隔整星期数
k:= i mod 7;//两日期间隔零星数,
// 关系: i = J * 7 + K;
wDays := j * 5;//一周五天工作
//计算零星数中的工作天数
for l := 0 to kdo
begin
if not (DayOfWeek(sDate + l) in [1,7]) then
wDays := wDays + 1;
end;
ShowMessage('两日期:'+DateToStr(DateTimePicker1.Date)+'和'+
DateToStr(DateTimePicker2.Date)+'间隔:'+ IntToStr(i)+ '天'+
' 其中工作日:'+ IntToStr(wDays)+'天');
end;