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. Comparing dates

Comparing dates

Scheduled Pinned Locked Moved C#
databasec++helptutorialquestion
6 Posts 4 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.
  • D Offline
    D Offline
    Demian Panello
    wrote on last edited by
    #1

    Hi. I'm writing an application that it use a SQL table for store and read data. Sometime, I need to list all the registers between two dates, (there is a field of type datetime in the table). So, I have to objects of type DateTime, ie, d1 and d2. Can anyone help me with the query string to list the registers between these two dates??. Table name: Table1 Field datetime: birth Query: "Select * from Table1 where birth > " + d1.toString() + " And birth <= " + d2.toString(); // It doesn't work. I also tried with "#" characters between DateTime objects, but it doesn't work anyway. Thanks.

    Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )

    P G 2 Replies Last reply
    0
    • D Demian Panello

      Hi. I'm writing an application that it use a SQL table for store and read data. Sometime, I need to list all the registers between two dates, (there is a field of type datetime in the table). So, I have to objects of type DateTime, ie, d1 and d2. Can anyone help me with the query string to list the registers between these two dates??. Table name: Table1 Field datetime: birth Query: "Select * from Table1 where birth > " + d1.toString() + " And birth <= " + d2.toString(); // It doesn't work. I also tried with "#" characters between DateTime objects, but it doesn't work anyway. Thanks.

      Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      You should not use string concatenation since it opens you up to sql injection attacks. Use parameterized queries instead.

      "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      D 1 Reply Last reply
      0
      • D Demian Panello

        Hi. I'm writing an application that it use a SQL table for store and read data. Sometime, I need to list all the registers between two dates, (there is a field of type datetime in the table). So, I have to objects of type DateTime, ie, d1 and d2. Can anyone help me with the query string to list the registers between these two dates??. Table name: Table1 Field datetime: birth Query: "Select * from Table1 where birth > " + d1.toString() + " And birth <= " + d2.toString(); // It doesn't work. I also tried with "#" characters between DateTime objects, but it doesn't work anyway. Thanks.

        Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )

        G Offline
        G Offline
        GuyThiebaut
        wrote on last edited by
        #3

        I'm not sure if this will work - give it a go anwyay: "Select * from Table1 where birth > cast(""" + d1.toString() + """as datetime) And birth <= cast(""" + d2.toString()+""" as datetime)" Regards Guy

        You always pass failure on the way to success.
        1 Reply Last reply
        0
        • P Paul Conrad

          You should not use string concatenation since it opens you up to sql injection attacks. Use parameterized queries instead.

          "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

          D Offline
          D Offline
          DannyAdler
          wrote on last edited by
          #4

          Paul Conrad wrote:

          You should not use string concatenation since it opens you up to sql injection attacks.

          Hi there Paul, Please explain your statement. Thanks in advance. Danny

          P 1 Reply Last reply
          0
          • D DannyAdler

            Paul Conrad wrote:

            You should not use string concatenation since it opens you up to sql injection attacks.

            Hi there Paul, Please explain your statement. Thanks in advance. Danny

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Read this article, http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer

            D 1 Reply Last reply
            0
            • P Paul Conrad

              Read this article, http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer

              D Offline
              D Offline
              DannyAdler
              wrote on last edited by
              #6

              Thanks man. Good info. Danny

              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