dare87 Posted May 14, 2008 Share Posted May 14, 2008 I have this query SELECT title, picurl AS url, details, DATE_FORMAT(start_date, '%M %d, %Y') AS sdate, DATE_FORMAT(start_date, '%M %d, %Y') AS edate FROM giveaway WHERE start_date >= '2008-5-13' and end_date <= '2008-5-20'" but I would like to change the end to WHERE start_date >= NOW() and end_date <= NOW() but in my db the date is stored as YYYY-MM-DD so it doesn't pull the info. Please help. Thanks Quote Link to comment Share on other sites More sharing options...
beebum Posted May 14, 2008 Share Posted May 14, 2008 Change NOW() to CURDATE(). Quote Link to comment Share on other sites More sharing options...
fenway Posted May 14, 2008 Share Posted May 14, 2008 but in my db the date is stored as YYYY-MM-DD so it doesn't pull the info. That doesn't make any sense. Quote Link to comment Share on other sites More sharing options...
beebum Posted May 14, 2008 Share Posted May 14, 2008 His date is stored as a DATE and he's trying to compare it directly to a DATETIME. NOW() is a DATETIME but CURDATE() is a DATE. mysql> select now() = curdate(); +-------------------+ | now() = curdate() | +-------------------+ | 0 | +-------------------+ 1 row in set (0.00 sec) mysql> select curdate() = curdate(); +-----------------------+ | curdate() = curdate() | +-----------------------+ | 1 | +-----------------------+ 1 row in set (0.00 sec) Quote Link to comment Share on other sites More sharing options...
fenway Posted May 14, 2008 Share Posted May 14, 2008 That's true for the equality only... for the inequality, mysql will silently do this type conversion for you. Quote Link to comment Share on other sites More sharing options...
beebum Posted May 14, 2008 Share Posted May 14, 2008 You're right. As far as I can tell, he just doesn't have any data that meets the search criteria. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.