给你段代码参考:
Private Sub Command1_Click()
hj = 0
rs.Open "select 生成日期, 完成日期 from 表1", cn, adOpenKeyset, adLockOptimistic
If rs.BOF = False And rs.EOF = False Then
rs.MoveFirst
Do While rs.EOF = False
n = DateDiff("d", rs.Fields("生成日期"), rs.Fields("完成日期"))
d = n
For i = 0 To n - 1
If Weekday(rs.Fields("生成日期") + i, vbMonday) = 6 Then d = d - 1
If Weekday(rs.Fields("生成日期") + i, vbMonday) = 7 Then d = d - 1
If Month(rs.Fields("生成日期") + i) = 1 And Day(rs.Fields("生成日期") + i) < 4 And Weekday(rs.Fields("生成日期") + i, vbMonday) <> 6 And Weekday(rs.Fields("生成日期") + i, vbMonday) <> 7 Then d = d - 1 '五一
If Month(rs.Fields("生成日期") + i) = 5 And Day(rs.Fields("生成日期") + i) < 4 And Weekday(rs.Fields("生成日期") + i, vbMonday) <> 6 And Weekday(rs.Fields("生成日期") + i, vbMonday) <> 7 Then d = d - 1 '十月一
'各种假日根据实际自己加入吧
Next
hj = hj + d
rs.MoveNext
Loop
pj = hj / rs.RecordCount
Text1.Text = pj
End If
rs.Close
End Sub