find data between 2 dates
-
hi i have in my access datetime filed that hold date in short format in this format: `01/08/2011` i have in my C# program datetimePicker that hold date in this format: `dt_from_A.Value.ToShortDateString()` and hold `01/08/2011` i try to run this query : SELECT * FROM ReturnConfTbl where Tdate >= #01/08/2011# and Tdate <= #01/08/2011# but i dont receive any records
-
hi i have in my access datetime filed that hold date in short format in this format: `01/08/2011` i have in my C# program datetimePicker that hold date in this format: `dt_from_A.Value.ToShortDateString()` and hold `01/08/2011` i try to run this query : SELECT * FROM ReturnConfTbl where Tdate >= #01/08/2011# and Tdate <= #01/08/2011# but i dont receive any records
in sql server, both of those dates default the time to midnight, not sure bout other db's but i assume its the same. If all you have is the one date you can use a some DATEADD function to add a day to it and just make the query Tdate < date + 1. all the db's i've seen have some form of that function as do most popular languages..even javascript can do it.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
hi i have in my access datetime filed that hold date in short format in this format: `01/08/2011` i have in my C# program datetimePicker that hold date in this format: `dt_from_A.Value.ToShortDateString()` and hold `01/08/2011` i try to run this query : SELECT * FROM ReturnConfTbl where Tdate >= #01/08/2011# and Tdate <= #01/08/2011# but i dont receive any records
goldsoft wrote:
filed that hold date in short format in this format: `01/08/2011`
Don't store dates as text/char; use a proper date/datetime datatype.
goldsoft wrote:
and hold `01/08/2011`
No, it holds a proper DateTime value; it simply displays the value in that format (or any other).
goldsoft wrote:
>= #01/08/2011# and Tdate <= #01/08/2011#
Use a parameterized query. Those two values are the same, so you will only get rows with exactly that value. You could use the AddDays method of the DateTime type to calculate the second value.
-
hi i have in my access datetime filed that hold date in short format in this format: `01/08/2011` i have in my C# program datetimePicker that hold date in this format: `dt_from_A.Value.ToShortDateString()` and hold `01/08/2011` i try to run this query : SELECT * FROM ReturnConfTbl where Tdate >= #01/08/2011# and Tdate <= #01/08/2011# but i dont receive any records
As PIEBALDconsult said, store dates and times in a proper DateTime, and hand them through as parameters. It is also worth noting that Access (like every other database I have seen) uses ISO format for dates anyway:
yyyy-MM-dd
so the query you tried would not work as the date format would cause an error.Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Manfred R. Bihy: "Looks as if OP is learning resistant."
-
hi i have in my access datetime filed that hold date in short format in this format: `01/08/2011` i have in my C# program datetimePicker that hold date in this format: `dt_from_A.Value.ToShortDateString()` and hold `01/08/2011` i try to run this query : SELECT * FROM ReturnConfTbl where Tdate >= #01/08/2011# and Tdate <= #01/08/2011# but i dont receive any records
This is a SQL question, not a C# question. You want to use the
BETWEEN
keyword in your SQL query:select * from table where table1.datecolumn BETWEEN date1 AND date2
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997