[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

regarding database filter

i have a database which captures date and time in the following format
08/26/2012 5:58:42 PM
i need to filter all the data created on 08/26/2012
i have a datepicker control in VB
i need to use the datepicker control to select the date which i will be using to filter the data.
how to do that coz if i am using the query "Select * from table where datefield =#" & datepicker1.value & "#"
nothing is returned as it will search for exact value of date picker that would be 08/26/2012  but the actual value of the table is 08/26/2012 5:58:42 PM. how to give the query for filtering this situation. please help
0
anbuvec
Asked:
anbuvec
  • 2
  • 2
1 Solution
 
itmarsolutionsCommented:
you have to give the time in your query

"Select * from table where datefield between '" & datepicker1.value.ToString("yyyy MMM DD") & " 00:00'" to '" & datepicker1.value.ToString("yyyy MMM DD") & " 23:59'"
0
 
anbuvecAuthor Commented:
.tostring is not an attribute or function and more over the database field type for date value is date/time field. i have tried the following and it gave me object required error
"Select tablefield from table where datefield between '" & DTPicker1.Value.ToString("MM DD yyyy") & " 00:00' to '" & DTPicker1.Value.ToString("MM DD yyyy") & " 23:59'".
0
 
owenacampbellCommented:
Hi,

You want to go ahead and use the SQL "LIKE" command. So if wanted to pick all the records from the table that were from 08/26/2012 i would do the following (amend the date formatting as required for your database)

SELECT * FROM TABLE WHERE date LIKE '%08/26/2102%'

Thanks
0
 
itmarsolutionsCommented:
did you can take the date part from the datepicker ?
0
 
anbuvecAuthor Commented:
Thank you so much owenacampbell... i was using the like command but i have missed the syntax i was using # instead of ' as that was a date field that is why i wanted to use = instead of like... it is just a syntax... but very quick and thank you for ur response... :D
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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now