参考下面的代码改一下
Dim dta As DataTable = DataTables("表A")
For Each dr As DataRow In dta.Select("开始时间 is not null and 结束时间 is not null")
For Each dc As DataCol In dta.DataCols
If dc.Name.StartsWith("A") OrElse dc.Name.StartsWith("B") Then
dr(dc.name) = Nothing
End If
Next
Dim tempd1 As Date
Dim tempd2 As Date
Dim d_start As Date = dr("开始时间")
Dim d_end As Date = dr("结束时间")
Dim d_m1 As Date = new Date(d_start.Year, 6, 30)
Dim d_e1 As Date = new Date(d_start.Year, 12, 31)
Dim idx As Integer = 0
If d_start <= d_m1 Then
tempd1 = d_start
If d_end <= d_m1 Then
tempd2 = d_end
Else
tempd2 = d_m1
idx = 1
End If
Else
tempd1 = d_start
If d_end <= d_e1
tempd2 = d_end
Else
tempd2 = d_e1
idx = 2
End If
End If
Dim sp As TimeSpan = tempd2 - tempd1
If tempd2 > new Date(tempd2.Year, 6, 30) Then
dr("B" & tempd2.Year) = sp.TotalDays
Else
dr("A" & tempd2.Year) = sp.TotalDays
End If
If idx > 0 Then
Dim d As Date = tempd2
Do While d < d_end
tempd1 = d.AddDays(1)
Dim d2 As Date = iif(idx Mod 2 = 0, d.AddMonths(6), d.AddMonths(6).AddDays(1))
If d2 >= d_end Then
tempd2 = d_end
Else
tempd2 = d2
End If
sp = tempd2 - tempd1
If tempd2 > new Date(tempd2.Year, 6, 30) Then
dr("B" & tempd2.Year) = sp.TotalDays
Else
dr("A" & tempd2.Year) = sp.TotalDays
End If
idx += 1
d = d2
Loop
End If
Next
[此贴子已经被作者于2016/12/2 11:39:04编辑过]