SQL Statement with DATE format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andre Stumpf

    SQL Statement with DATE format

    Hi,

    i want to compare dates. The dates are like "2007-06-25".
    I tried this:
    $SQLString = "SELECT * FROM myDB.myTABLE WHERE dat_start = $act_dat";
    But it didn't work.
    What can I do?
    Thank you!

    André

  • james.gauth@googlemail.com

    #2
    Re: SQL Statement with DATE format

    On 25 Jun, 11:39, Andre Stumpf <andre.stu...@s tumpfi.comwrote :
    Hi,
    >
    i want to compare dates. The dates are like "2007-06-25".
    I tried this:
    $SQLString = "SELECT * FROM myDB.myTABLE WHERE dat_start = $act_dat";
    But it didn't work.
    What can I do?
    Thank you!
    >
    André
    This problem is more than likely due to your dates not being inside
    quotes in the SQL query. When substitution takes place, your SQL
    string should end up similar to this:

    SELECT * FROM myDB.myTABLE WHERE dat_start = '2007-06-25'

    Whereas without quotes the query would fail because of the unquoted
    literal:

    SELECT * FROM myDB.myTABLE WHERE dat_start = 2007-06-25

    If the dates are coming from user input, be careful not to allow a SQL
    injection exploit

    Comment

    • Andre Stumpf

      #3
      Re: SQL Statement with DATE format

      On 25 Jun., 13:24, james.ga...@goo glemail.com wrote:
      This problem is more than likely due to your dates not being inside
      quotes in the SQL query. When substitution takes place, your SQL
      string should end up similar to this:
      >
      SELECT * FROM myDB.myTABLE WHERE dat_start = '2007-06-25'
      Hi James,

      the dates inside quotes works fine!
      Thank you.

      André

      Comment

      Working...