SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot daveporter's Avatar
    Join Date
    Mar 2002
    Location
    Perth, Western Australia
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select with date = fails

    I have the following select statement.

    echo "<p>The Current Date Is: ".$the_date;
    $query = "select * from `quiz` where quizdate = $the_date";
    $result = $db->query($query);
    $num_results = $result->num_rows;

    $the_date contains the date I want, but the $query is failing, but the quiz table contains an entry with the same date...

    I know dates can be tricky. The quizdate field is format date and it looks like:
    2009-05-01

    TIA, Dave

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You need single quotes around that date string in the query.

    Also, if your column isn't a date but a datetime or timestamp, it won't be equal unless the time matches as well ('2009-05-01' will be treated as midnight on that date).

  3. #3
    SitePoint Zealot daveporter's Avatar
    Join Date
    Mar 2002
    Location
    Perth, Western Australia
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan, yes that was it !
    & yes the field is a straight date field.
    cheers Dave


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •