Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Between 2 Dates 1

Status
Not open for further replies.

net123

Programmer
Oct 18, 2002
167
US
I have a btnSearch_Click event in which it searches a DB with all the data that is between the entered date and today's date. Here is my logic:

Dim TodayDT As DateTime
TodayDT = DateTime.Now

...
"AND Convert(char(10),dbo.Table1.ThisDate,101) BETWEEN '" & txtThisDate.Text & "' AND '" & TodayDT.ToString("{0:MM/dd/yyyy}") & "' " & _
[/blue]

Nothing returns on the ASP.NET page. Does someone see something wrong in my logic?
 
What happens when you run the query in QueryAnalyzer or the interactive SQL tool that comes with your database?

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
"AND Convert(char(10),dbo.Table1.ThisDate,101) BETWEEN '" & txtThisDate.Text & "' AND '" & TodayDT.ToString("{0:MM/dd/yyyy}") & "' " & _

I would change this to the following

"AND dbo.Table1.ThisDate BETWEEN Convert(DateTime," & txtThisDate.Text & ",101) AND GETDATE()" & _

It works for me. The way you were doing it, you were comparing the text values instead of the date values.

Hope everyone is having a great day!

Thanks - Jennifer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top