Android Question A Date comparator

Lary Yenta

Member
Licensed User
Longtime 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
 
Hi Lary,
it will be much more easier to read your code when you use the code-Tags like:
Code: Copy
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
 
Upvote 0
Oki dokie, I am very obviously making a major error here Here is the code I am trying to implement

Code: Copy
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?
 
Upvote 0
Please post the solution for future references
 
Upvote 0
Sorry bout that, I was just working onb making things look pretty.

All it took was the following:
Code: Copy
    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
 
Upvote 0
Back
Top