Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. find data between 2 dates

find data between 2 dates

Scheduled Pinned Locked Moved C#
csharpdatabase
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goldsoft
    wrote on last edited by
    #1

    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

    S P OriginalGriffO R 4 Replies Last reply
    0
    • G goldsoft

      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

      S Offline
      S Offline
      SomeGuyThatIsMe
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • G goldsoft

        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

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G goldsoft

          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

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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."

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          1 Reply Last reply
          0
          • G goldsoft

            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

            R Offline
            R Offline
            realJSOP
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups