Solved

Datetimepicker records filter

Posted on 2009-05-12
5
261 Views
Last Modified: 2012-05-06
Hello,

I have a DateTimePicker on a form. The DateTimePicker is formated as Short date, so the result of dtpReport .Text is something like 12-05-2009.
I have a SQL table with a field date (smalldate format) with values like 13-05-2009 7:52:32.
I have the following SQL statment to filter my records:

SQL = "SELECT coord.coord, DefectsReg.data, DefectsTipo.tipo, DefectsReg.lado, kenn.modelo FROM coord INNER JOIN DefectsReg ON coord.defeito = DefectsReg.id INNER JOIN DefectsTipo ON DefectsReg.type = DefectsTipo.id INNER JOIN kenn ON DefectsReg.kenn = kenn.id WHERE (DefectsReg.data >= CONVERT(DATETIME, '" & dtpDataRelatorio.Text & "', 102))"

wich is giving me this result:

SELECT coord.coord, DefectsReg.data, DefectsTipo.tipo, DefectsReg.lado, kenn.modelo FROM coord INNER JOIN DefectsReg ON coord.defeito = DefectsReg.id INNER JOIN DefectsTipo ON DefectsReg.type = DefectsTipo.id INNER JOIN kenn ON DefectsReg.kenn = kenn.id WHERE (DefectsReg.data >= CONVERT(DATETIME, '12-05-2009', 102))

but now records are been displayed. Can someone help me please?

Thanks,

jppinto
0
Comment
Question by:jppinto
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
ID: 24372208
If the time factor is not important then try using this:
CONVERT(DATETIME, dtpDataRelatorio
.Value.ToString("yyyy-MM-dd 23:59:59")
0
 
LVL 33

Author Comment

by:jppinto
ID: 24372553
Incorrect syntax error!
0
 
LVL 11

Accepted Solution

by:
Muhammad Ousama Ghazali earned 500 total points
ID: 24372883
Try now using either of the options mentioned in snippet below:

'OPTION 1

SQL = "SELECT coord.coord, DefectsReg.data, DefectsTipo.tipo, DefectsReg.lado, kenn.modelo FROM coord INNER JOIN DefectsReg ON coord.defeito = DefectsReg.id INNER JOIN DefectsTipo ON DefectsReg.type = DefectsTipo.id INNER JOIN kenn ON DefectsReg.kenn = kenn.id WHERE (DefectsReg.data >= CONVERT(DATETIME, '" & dtpDataRelatorio.Value.ToString("yyyy-MM-dd 23:59:59") & "')"
 

'OPTION 2

SQL = "SELECT coord.coord, DefectsReg.data, DefectsTipo.tipo, DefectsReg.lado, kenn.modelo FROM coord INNER JOIN DefectsReg ON coord.defeito = DefectsReg.id INNER JOIN DefectsTipo ON DefectsReg.type = DefectsTipo.id INNER JOIN kenn ON DefectsReg.kenn = kenn.id WHERE (DefectsReg.data >= CONVERT(DATETIME, '" & dtpDataRelatorio.Value.ToString("yyyy-MM-dd 23:59:59") & "', 102)"

Open in new window

0
 
LVL 33

Author Comment

by:jppinto
ID: 24373123
The first solution worked. I've changed the 23:59:59 to 00:00:00 to get the records from the complete day.

Thanks,

jppinto
0
 
LVL 11

Expert Comment

by:Muhammad Ousama Ghazali
ID: 24373385
That's good if it worked for you. Just remember when you wish to compare two dates, follow the same but put 00:00:00 in Start Date and 23:59:59 in the End Date.
Happy programming.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now