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. Visual Basic
  4. search between two dates

search between two dates

Scheduled Pinned Locked Moved Visual Basic
csharpdatabase
9 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.
  • W Offline
    W Offline
    waner michaud
    wrote on last edited by
    #1

    Hi, I have form that has a date_from and date_to.. One table (id, reg_no, reg_date, desc) I want to search between those two dates from the form against reg_date on the table.. Using vb.net and sql express.. Thanks in advance

    T D L 3 Replies Last reply
    0
    • W waner michaud

      Hi, I have form that has a date_from and date_to.. One table (id, reg_no, reg_date, desc) I want to search between those two dates from the form against reg_date on the table.. Using vb.net and sql express.. Thanks in advance

      T Offline
      T Offline
      Thomas Krojer
      wrote on last edited by
      #2

      this can be done in sql with the 'between' construct in the 'where' clause.

      1 Reply Last reply
      0
      • W waner michaud

        Hi, I have form that has a date_from and date_to.. One table (id, reg_no, reg_date, desc) I want to search between those two dates from the form against reg_date on the table.. Using vb.net and sql express.. Thanks in advance

        D Offline
        D Offline
        Dr Walt Fair PE
        wrote on last edited by
        #3

        What he said. If you want more flexibility you can also use something like "SELECT * FROM table WHERE (reg_date > " & MyDate1 & ") and (reg_date < " & MyDate2 & ")"

        CQ de W5ALT

        Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

        W 1 Reply Last reply
        0
        • D Dr Walt Fair PE

          What he said. If you want more flexibility you can also use something like "SELECT * FROM table WHERE (reg_date > " & MyDate1 & ") and (reg_date < " & MyDate2 & ")"

          CQ de W5ALT

          Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

          W Offline
          W Offline
          waner michaud
          wrote on last edited by
          #4

          Thanks, I tried this: Select * from FireArmsTD_View Where (FrireArms_date > " & DateFrom & ") And (FrireArms_date < " & DateFrom & ") I got invalid column name for both ' & DateFrom & ' and ' & DateTo & ' thanks

          D S 2 Replies Last reply
          0
          • W waner michaud

            Thanks, I tried this: Select * from FireArmsTD_View Where (FrireArms_date > " & DateFrom & ") And (FrireArms_date < " & DateFrom & ") I got invalid column name for both ' & DateFrom & ' and ' & DateTo & ' thanks

            D Offline
            D Offline
            Dr Walt Fair PE
            wrote on last edited by
            #5

            As written, your "s are not correct and DateFrom is shown twice, but I'll assume those are just typo's. Make sure that DateFrom and DateTo are showing up as strings. I guess I forgot to mention that, and that they need to be enclosed in quotes. I usually create a string variable to check while debugging.

            CQ de W5ALT

            Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

            1 Reply Last reply
            0
            • W waner michaud

              Hi, I have form that has a date_from and date_to.. One table (id, reg_no, reg_date, desc) I want to search between those two dates from the form against reg_date on the table.. Using vb.net and sql express.. Thanks in advance

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Two warnings: 1. IIRC the SQL BETWEEN keyword is a bit dangerous as different implementations use different definitions; the issue is inclusive versus exclusive, i.e. does an exact match with a border get included or not. Read the doc, or use explicit comparisons. 2. Use SQLParameter to avoid all datetime formatting and regional settings issues; it's much better/cleaner/safer than string concatenation anyway. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              modified on Thursday, November 4, 2010 12:58 PM

              W 1 Reply Last reply
              0
              • L Luc Pattyn

                Two warnings: 1. IIRC the SQL BETWEEN keyword is a bit dangerous as different implementations use different definitions; the issue is inclusive versus exclusive, i.e. does an exact match with a border get included or not. Read the doc, or use explicit comparisons. 2. Use SQLParameter to avoid all datetime formatting and regional settings issues; it's much better/cleaner/safer than string concatenation anyway. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                modified on Thursday, November 4, 2010 12:58 PM

                W Offline
                W Offline
                waner michaud
                wrote on last edited by
                #7

                Hi, I am a novice, just don't know how. will you guide me? thanks

                L 1 Reply Last reply
                0
                • W waner michaud

                  Hi, I am a novice, just don't know how. will you guide me? thanks

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  The documentation and examples on SQLParameter are plenty, maybe you want to read Beginners guide to accessing SQL Server through C#[^] which uses C# but the same types and ideas are valid in VB.NET :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  1 Reply Last reply
                  0
                  • W waner michaud

                    Thanks, I tried this: Select * from FireArmsTD_View Where (FrireArms_date > " & DateFrom & ") And (FrireArms_date < " & DateFrom & ") I got invalid column name for both ' & DateFrom & ' and ' & DateTo & ' thanks

                    S Offline
                    S Offline
                    Scubapro
                    wrote on last edited by
                    #9

                    Try this:

                    select * from FireArmsTD_View
                    where FrireArms_date between to_date('&DateFrom','mm-dd-yyyy') and to_date('&DateTo','mm-dd-yyyy')

                    Btw, is better to use the 'Database Board' for these kind of questions.

                    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