SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Query retrun empty record

    hi to all,

    i execute these query but these return empy result although record exist between these dates

    SELECT * FROM nisanj_users WHERE reminder_datum BETWEEN '2009-02-20' AND '2009-02-10'

    or

    SELECT * FROM nisanj_users WHERE reminder_datum < '2009-02-20' AND reminder_datum > '2009-02-10'

    i want to get all records between two dates from mysql

    regards,

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    the first one is obviously wrong, because this --
    Code:
    WHERE reminder_datum BETWEEN '2009-02-20' AND '2009-02-10'
    is equivaluent to this --
    Code:
    WHERE reminder_datum >= '2009-02-20' 
      AND reminder_datum <= '2009-02-10'
    and of course that's impossible for all values

    the second one should work
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    '2009-02-10' is a valid mysql date string, there's no need to cast it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by r937 View Post
    '2009-02-10' is a valid mysql date string, there's no need to cast it
    Ok. That's what I thought too. But then I read this in the MySQL reference manual:
    "If you use a string constant such as '2001-1-1' in a comparison to a DATE, cast the string to a DATE."

    And I thought that it might be worth a try, since the OP is claiming his 2nd query (the one that should work), isn't working.


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
  •