Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SQL Server And Visual Basic 6.0 Date Range

Posted on 2003-03-24
6
Medium Priority
?
174 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

564 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