...

View Full Version : Searching Only DATE on DATETIME



tomyknoker
07-19-2007, 02:27 PM
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...


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

Fumigator
07-19-2007, 02:57 PM
Wrap the DATETIME column in the MySQL DATE() function.



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

tomyknoker
07-19-2007, 03:18 PM
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?

Fumigator
07-19-2007, 05:11 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum