Home > Mobile >  How to compare againts 24hour time VB.NET
How to compare againts 24hour time VB.NET

Time:08-25

...      
SQLText &= " AND P.AppointmentDate >= #" & VarMatchDate & "#"
SQLText &= " AND P.AppointmentTime >= #" & Now & "#"

In the MS Access Database I have Times like 15:00, 20:00. When I do the above query its not returning the result I am hoping for. The AppointmentDate work as expected but the time is returning the result I am trying to avoid.

So I would like to show all the future appointment so if there is an appointment at 14:15 and its 14:16 the record at 14:15 should no longer show.

CodePudding user response:

There are a couple of ways to achieve this. Using your current code then convert the dates to Universal format like:

SQLText &= " AND P.AppointmentDate >= #" & VarMatchDate.ToString(“u”) & "#"
SQLText &= " AND P.AppointmentTime >= #" & Now.ToString(“u”) & "#"

But better to use parameters and pass the values into the query object like:

SQLText &= " AND P.AppointmentDate >= @AptDate”
SQLText &= " AND P.AppointmentTime >= @AptTime”
Dim command as new SqlCommand(SQLText, connection)
command.Parameters.Add("@AptDate”, SqlDbType.DateTime)
command.Parameters.Add("@AptTime”, SqlDbType.DateTime)
command.Parameters("@AptDate").Value = VarMatchDate
command.Parameters("@AptTime").Value = Now
  • Related