Android Question A Date comparator

Discussion in 'Android Questions' started by Lary Yenta, Apr 8, 2015.

  1. Lary Yenta

    Lary Yenta Member Licensed User

    Hey there,

    A quick question here, I would like to filter certain data in my measurement table That data would be based upon data later than a given date. My table has a field that is mDate (A Text Field) and a query I have written looks like that below.

    Sub CheckMs2Count
    Dim Cursor2, Cur As Cursor
    Cursor2 = SQL2.ExecQuery("SELECT measure.Glucose FROM measure inner join users on users.ID = measure.UserID where measure.UserID = " & edtID.Text & _
    " AND measure.mDate >= " & edtDte.Text)
    If Cursor2.RowCount <> 0 Then
    RNum2 = Cursor2.RowCount
    MsGlIDList.Initialize
    If Cursor2.RowCount > 0 Then
    For Rw1 = 0 To RNum2 - 1
    Cursor2.Position = Rw1
    MsGlIDList.Add(Cursor2.GetDouble("Glucose"))
    Next
    End If
    Cursor2.Close
    ToastMessageShow("Records: " & RNum2, True)
    End If

    Cur = SQL2.ExecQuery("SELECT measure.mDate, measure.mTime FROM measure inner join users on users.ID = measure.UserID where measure.UserID = " & _
    edtID.Text & " AND measure.mDate >= " & edtDte.Text)
    If Cur.RowCount <> 0 Then
    RNumD = Cur.RowCount
    MsDATESList.Initialize
    If Cur.RowCount > 0 Then
    For Rw1 = 0 To RNumD - 1
    Cur.Position = Rw1
    MsDATESList.Add(Cur.GetString("mDate") & " " & Cur.GetString("mTime"))
    Next
    End If
    Cur.Close
    ToastMessageShow("Records: " & RNumD, True)
    End If

    End Sub

    I know that I should probably use one of the functions in the dateutils library but which one3?

    Thanks in advance,

    Lary
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    Why don't you use ExecuteQuery2 and pass the values as parameters?

    You need to parse the date with DateTime.DateParse and then you will be able to compare the ticks values. Make sure to use Long fields to hold the ticks.
     
  3. eurojam

    eurojam Well-Known Member Licensed User

    Hi Lary,
    it will be much more easier to read your code when you use the code-Tags like:
    Code:
    Sub CheckMs2Count
    Dim Cursor2, Cur As Cursor
    Cursor2 = SQL2.ExecQuery(
    "SELECT measure.Glucose FROM measure inner join users on users.ID = measure.UserID where measure.UserID = " & edtID.Text & _
    " AND measure.mDate >= " & edtDte.Text)
    If Cursor2.RowCount <> 0 Then
        
    '....do anything
    End If
    Cursor2.Close

    ToastMessageShow("Records: " & RNumD, True)
    End sub
    cheers
    stefan
     
    Erel likes this.
  4. Lary Yenta

    Lary Yenta Member Licensed User

    Yeah, sorry bout that gentlemen!

    lary
     
  5. Lary Yenta

    Lary Yenta Member Licensed User

    Oki dokie, I am very obviously making a major error here Here is the code I am trying to implement

    Code:
    Sub btnDummy_Click
      
    Dim dates(RC) As Long
       CheckMeasCount
       RC=MsGlIDList.Size
       
    'StartActivity(SimpleGraph)
       DateTime.DateFormat = "yyyy-MM-dd"
       
    DateTime.TimeFormat = "HH:mm"
       MsD2List.Initialize
       DtValue = 
    DateTime.DateParse(edtDte.Text)
      
    For i = 0 To RC-1
         
    Dim datesplit() As String  'define an array to hold the date and time after we split it   
         datesplit = Regex.Split(" ", MsDATESList.Get(i)) 'split Date and  Time at the Space between Date and Time ex.  "2015-1-16 14:30"
         'Log("epoch: " & DateTime.DateTimeParse(datesplit(0), datesplit(1)))
         dates(i) = DateTime.DateTimeParse(datesplit(0), datesplit(1))  'convert date and time to epoch values so that the graph library can use them
        If dates(i) >= DtValue Then
          MsD2List.Add(MsDATESList.Get(i))
         
    End If
         
       
    Next
       
    ToastMessageShow("Number of Rows: " & MsD2List.Size, True)
       
    End Sub
    I get an error at the line dates(i) = Datetime.DateTimeParse......Can someonesuggest what I am doing wrong?
     
  6. Lary Yenta

    Lary Yenta Member Licensed User

    Oki Dokie, so I am a dummy, I got it figured out and it kicks butt!!!!!
     
  7. DonManfred

    DonManfred Expert Licensed User

    Please post the solution for future references
     
  8. Lary Yenta

    Lary Yenta Member Licensed User

    Sorry bout that, I was just working onb making things look pretty.

    All it took was the following:
    Code:
    If DateTime.DateTimeParse(datesplit(0),datesplit(1)) >= DtValue Then
          MsD2List.Add(MsDATESList.Get(i))
           MsGl2List.Add(MsGlIDList.Get(i))
         
    End If
    And that was it!

    Lary
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice