SQL Date Help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have written a program that saves a date and time field as:

4/22/2005 6:30:00 PM

I want the user to click a date in a calendar control, and then populate a
data grid with the data for only the date the user clicked. I don't care
about the time, I want to use SQL to search for the date in the beginning of
the field.

My SQL statement is as follows:

sql = "SELECT CalendarDateTime, Appointment From Calendar " & _
"WHERE CalendarDateTime LIKE '#" & Me.labelSelectedDate.Text & "#%' ORDER
BY CalendarDateTime"

I am doing something wrong because my DataGrid does not show any data. If i
change the statement to a generic SELECT * FROM Calendar, the data is
displayed. I know I have an error in my SQL statement.

Any Ideas?
 
Try using the convert function like this example from the Northwind db.

mysql = "select * from orders where Convert(varchar, orderdate, 101) =
'12/09/1996' "

or

mysql = "select * from orders where Convert(varchar, orderdate, 101) = '" &
lblDate.Text & "'"


I have written a program that saves a date and time field as:

4/22/2005 6:30:00 PM

I want the user to click a date in a calendar control, and then populate a
data grid with the data for only the date the user clicked. I don't care
about the time, I want to use SQL to search for the date in the beginning of
the field.

My SQL statement is as follows:

sql = "SELECT CalendarDateTime, Appointment From Calendar " & _
"WHERE CalendarDateTime LIKE '#" & Me.labelSelectedDate.Text & "#%' ORDER
BY CalendarDateTime"

I am doing something wrong because my DataGrid does not show any data. If i
change the statement to a generic SELECT * FROM Calendar, the data is
displayed. I know I have an error in my SQL statement.

Any Ideas?
 
Back
Top