Solved

Datetimepicker records filter

Posted on 2009-05-12
5
264 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - Windows Protected Your PC 7 41
sql help 2 45
SQL Query - Database name 'TempDB' ignored, referencing object in tempdb - Error 2 30
Help with error in Query 2 31
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

789 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