【发布时间】:2010-05-13 17:41:03
【问题描述】:
我需要根据日期范围过滤数据。
我的表有一个字段处理日期。我需要过滤记录并显示 FromDate 到 ToDate 范围内的记录。
如何在 VB.NET 中编写一个函数来帮助我过滤数据。
我走对了吗?
【问题讨论】:
标签: asp.net javascript filter
我需要根据日期范围过滤数据。
我的表有一个字段处理日期。我需要过滤记录并显示 FromDate 到 ToDate 范围内的记录。
如何在 VB.NET 中编写一个函数来帮助我过滤数据。
我走对了吗?
【问题讨论】:
标签: asp.net javascript filter
您为什么不帮自己一个忙并使用 DateTime。解析您的字符串并使用日期比较运算符
有点像
Function ObjectInRange(ByRef obj As Object, ByVal str1 As String, ByVal str2 As String) As Boolean
Dim date1 As DateTime = DateTime.Parse(str1)
Dim date2 As DateTime = DateTime.Parse(str2)
Dim inRange = False
For Each prop As PropertyInfo In obj.GetType().GetProperties()
Dim propVal = prop.GetValue(obj, Nothing)
If propVal Is Nothing Then
Continue For
End If
Dim propValString = Convert.ToString(propVal)
Dim propValDate = DateTime.Parse(propValString)
If propValDate.CompareTo(date1) > 0 And propValDate.CompareTo(date2) < 0 Then
inRange = True
Exit For
End If
Next
Return inRange
End Function
【讨论】: