Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Searching Only DATE on DATETIME

    I have a DATETIME filed in my database... I am only want to search the DATE though is this possible? I output my search result as this...

    PHP Code:
    SELECT tblmembers WHERE `loginDateTime` >= '2007-05-22' && `loginDateTime` <= '2007-05-22' ORDER BY `LastName
    And I guess it returns no results because it's looking for something like 2007-05-22 22:09:30, atleast that's my hunch... So without having to change the field in my database to just DATE is there anyway around this? Hopefully this makes sense to somebody...

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Wrap the DATETIME column in the MySQL DATE() function.

    PHP Code:
    $query "
    SELECT * as tblmembers
    WHERE DATE(loginDateTime) BETWEEN '2007-05-22' AND '2007-05-22'
    ORDER BY LastName  
    "


  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Fumigator worked a treat! So I didn't need to mess around with all the code above I had? This is what I find frustrating about code, so many ways to do it... Would your's be the more correct way?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I replaced your >= and <= checks with a BETWEEN is about all I changed (other than adding the DATE() function of course). Either way works... BETWEEN is a bit more straightforward.


  •  

    Posting Permissions

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