【问题标题】:Filter records based on Date Range + ASP.NET + Regex + Javascript基于日期范围 + ASP.NET + 正则表达式 + Javascript 过滤记录
【发布时间】:2010-05-13 17:41:03
【问题描述】:

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

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

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

我走对了吗?

【问题讨论】:

    标签: asp.net javascript filter


    【解决方案1】:

    您为什么不帮自己一个忙并使用 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
    

    【讨论】:

    • 是的,我做了类似的事情......我只是想太多......无论如何,谢谢!
    猜你喜欢
    • 2017-10-06
    • 1970-01-01
    • 2021-11-01
    • 1970-01-01
    • 2016-06-22
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多