Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
DataColChanged事件:
Select Case e.DataCol.Name
Case "日期A","日期B"
If e.DataRow.IsNull("日期A") OrElse e.DataRow.IsNull("日期B") Then
e.DataRow("日期AB列相隔时间") = Nothing
Else
Dim y,m,d As Integer
Dim d1 As Date = e.DataRow("日期A")
Dim d2 As Date = e.DataRow("日期B")
y = d2.Year - d1.Year
m = d2.Month - d1.Month
d = d2.day - d1.day
If m = 0 OrElse (m = 0 AndAlso d < 0) Then
y = y - 1
m = m + 12
End If
If d < 0 Then
m = m - 1
d = Date.DaysInMonth(d1.Year,d1.Month) + d
End If
Dim s As String
If y > 0 Then
s = y & "年"
End If
If m > 0 Then
s = s & m & "个月"
End If
If d > 0 Then
s = s & d & "日"
End If
e.DataRow("日期AB列相隔时间") = s
End If
End Select
谢谢贺老师!
还有一个问题,如果两日期列为同年同月 显示的就为12个月 如 日期A 为2010-11-28 日期B 为2010-11-30 结果成了12个月2日.正确结果应该是 2日,这不知道是哪里的问题。
是我手误,将<打成=了,正确的:
Select Case e.DataCol.Name
Case "日期A","日期B"
If e.DataRow.IsNull("日期A") OrElse e.DataRow.IsNull("日期B") Then
e.DataRow("日期AB列相隔时间") = Nothing
Else
Dim y,m,d As Integer
Dim d1 As Date = e.DataRow("日期A")
Dim d2 As Date = e.DataRow("日期B")
y = d2.Year - d1.Year
m = d2.Month - d1.Month
d = d2.day - d1.day
If m < 0 OrElse (m = 0 AndAlso d < 0) Then
y = y - 1
m = m + 12
End If
If d < 0 Then
m = m - 1
d = Date.DaysInMonth(d1.Year,d1.Month) + d
End If
Dim s As String
If y > 0 Then
s = y & "年"
End If
If m > 0 Then
s = s & m & "个月"
End If
If d > 0 Then
s = s & d & "日"
End If
e.DataRow("日期AB列相隔时间") = s
End If
End Select
谢谢!这个就完全正确。
能不能增加本年第一天、上月最后一天、本月第一天、本月最后一天、本年最后一天的函数。
能不能增加本年第一天、上月最后一天、本月第一天、本月最后一天、本年最后一天的函数。
近似的帮助中可以找到啊~ DaysInMonth
好像没什么必要,太简单了,自己写一下也无妨。
Dim d As Date = Date.Today
Output.Show("本年第一天:" & New Date(d.Year,1,1))
Output.Show("本年最后一天:" & New Date(d.Year,12,Date.DaysInMonth(d.Year,1)))
Output.Show("本月第一天:" & New Date(d.Year,d.Month,1))
Output.Show("本月最后一天:" & New Date(d.Year,12,Date.DaysInMonth(d.Year,d.Month)))