Select Case e.DataCol.name
Case "起日期","止日期","月利率","本金金额"
If e.DataRow.IsNull("起日期") OrElse e.DataRow.IsNull("止日期") Then
e.DataRow("天数") = Nothing
Else
Dim y,m,d As Integer
Dim dt1 As Date = e.DataRow("起日期")
Dim dt2 As Date = e.DataRow("止日期")
DateYMD(dt1,dt2,y,m,d)
dt1 = dt1.AddYears(y)
d= (dt2- dt1).TotalDays()
e.DataRow("天数") = d
e.DataRow("月利率") =10
e.DataRow("利息")= e.DataRow("本金金额")* e.DataRow("月利率") * e.DataRow("天数") /30000
End If
End Select
按上面代码计算e.DataRow("天数") 如果起日期为2018-04-16 止日期为2019-04-16 结果为0。不跨年计算是对的,跨年就无法计算