根据日期范围+ ASP.NET + Regex + Javascript过滤记录

时间:2010-05-13 17:41:04

标签: asp.net javascript filter

我需要根据日期范围过滤数据。

我的表格有一个字段处理日期。我需要过滤记录并显示FromDate到ToDate范围内的记录。

如何在VB.NET中编写一个可以帮助我过滤数据的函数。

我是否在正确的轨道上?

1 个答案:

答案 0 :(得分:1)

为什么不给自己一个忙,DateTime.Parse你的字符串并使用日期比较运算符

这样的东西
 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
相关问题