我试图计算两个日期之间的日期,不包括周六和星期日。我已经写到目前为止VB.NET - 计算排除日期之间的两个日期之间的天数
Dim startDay As Integer
Dim endDay As Integer
Dim days As Integer
Dim count As Integer
startDay = dtpStartDate.Value.DayOfWeek
endDay = dtpEndDate.Value.DayOfWeek
For days = startDay To endDay
If days = 0 Or days = 6 Then 'Sunday = 0, Saturday = 6
count += 1
End If
Next
lblNoOfDays.Text = count
,如果你选择在同一个星期内,这两个日期,它工作正常此代码。 (例如:1月23日至1月27日给出结果5) 但是,如果我将它们设置为不同星期的日期(例如:1月23日至1月30日给出结果1),它会给出不正确的结果。
我知道这是因为循环发生,但我想不出一种方法来克服这一点。任何人都可以给我一个建议,解决?
谢谢
这个问题已经前已问:http://stackoverflow.com/questions/165887/ net-date-compare-count-the-amount-of-working-days-a-date,http://stackoverflow.com/questions/6710296/count-the-number-of-weekdays-between-two- date-in-visual-basic – 2012-01-29 17:42:04