以下是引用有点色在2016/12/2 9:48:00的发言:
参考下面的代码改一下
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 d_m2 As Date = new Date(d_end.Year, 6, 30)
Dim d_e2 As Date = new Date(d_end.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 d1 As Date = iif(idx Mod 2 = 0, d_m2, d_e2)
Dim d2 As Date = iif(idx Mod 2 = 0, d.AddMonths(6), d.AddMonths(6).AddDays(1))
If d2 >= d1 Then
tempd2 = d1
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
有点色大神 请挪步 名称为 再次求教关于时间分段问题 ,那个帖子,我再那个帖子的附件中更改了列 这个帖子作废了,之前的技术员他请事假一个月,我一个做财务的基本不会,原来的软件打不开了,所以我自己做了个表 就是想计算几个数据,求您帮我弄下,不是当您是免费的代码编译器。。。再次感谢 有点色 工程师,求您帮个忙哈