Solved

Datetimepicker records filter

Posted on 2009-05-12
5
269 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
[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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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