views:

100

answers:

2

Hi

I need to filter data based on a date range.

My table has a field Process date. I need to filter the records and display those in the range FromDate to ToDate.

How do I write a function in VB.NET which can help me filter the data.

Am I on the right track??

A: 

str1 and str2 are dates in String format

ASIF
this should be a comment or an edit to the original question
Midhat
+1  A: 

Why dont you do yourself a favor and DateTime.Parse your strings and use Date comparison operators

Something like

 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
Midhat
Yeah I did something like that... I was just thinking too much.. thanks anyway!
ASIF