?
Solved

SQL Server And Visual Basic 6.0 Date Range

Posted on 2003-03-24
6
Medium Priority
?
164 Views
Last Modified: 2013-11-25
Hello,

I am trying to do a search on a SQL Server table based on the date/time value.  The column is defined as "smalldatetime" and I want to pull all the records that fall between the date range.  I have two datepicker controls for the user to select the control and they are set for "vbshortDate".  I know I am doing something stupid and I am overlooking something very easy.  I know I have type mismatch problems and I have lot of different methods and have no luck so far.

Set MainBreakRs = MainBreakConn.Execute("Select WaterOffId, Convert(Varchar(20), TimeReceived, 0), " & _
"ValveDownId, StreetName, FromStreet, " & _
"ToStreet, Convert(Varchar(20), DateOff, 0), Convert(Varchar(20), EstDate,0), Convert(Varchar(20), DateOn, 0), CrewNo, Comments, " & _
"EditedBy, ModifiedBy, Convert(Varchar(20), ModifiedDate, 0) from WaterOff " & _
"where TimeReceived between '" & dtWateroffDateReceivedSearchFrom.Value & _
"' and '" & dtWaterToDateReceivedSearchtTo.Value & _
"' order by timereceived DESC ")

I have tried CONVERT(varchar(10), timereceived, 101) for the timereceived column and I have also tried CAST along with that to try to make it work. I have tried using FormatDateTime(dtWaterOffDateReceivedSearchFrom.value, vbshortDate/vbgeneraldate) and Fort(dtWaterOffDateReceivedSearchFrom.value, "MM/DD/YYYY") with no luck...

I need an extra set of eyes to take a look at this because I got tired.  Thanks and any help is appreciated,

Raj
0
Comment
Question by:RajAntonyV
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 4

Expert Comment

by:trkcorp
ID: 8197693
Well I am not altogether certain that I understand all of the problems you are having but I do see one potential problem.  When selecting a date range the dates should include time, otherwise you may not get all of the data you expect. (the last day will be missing) I would change my WHERE clause to something like this:
"where TimeReceived between '" & dtWateroffDateReceivedSearchFrom.Value & " 00:00:01' and '" & dtWaterToDateReceivedSearchtTo.Value & " 24:59:59' order by timereceived DESC ")
0
 
LVL 4

Accepted Solution

by:
trkcorp earned 1000 total points
ID: 8197705
OOPS - end time should read 23:59:59
0
 

Author Comment

by:RajAntonyV
ID: 8198403
Hi,

Thank you.  Your solution worked.  You just made my day!!!

Take care and appreciate all your help,

Raj Antony V
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:trkcorp
ID: 8198738
So... accept my answer...
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 8204561
???
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 8205484
You're welcome!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question