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 Link to comment https://forums.phpfreaks.com/topic/105528-solved-convert/ Share on other sites More sharing options...
beebum Posted May 14, 2008 Share Posted May 14, 2008 Change NOW() to CURDATE(). Link to comment https://forums.phpfreaks.com/topic/105528-solved-convert/#findComment-540886 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. Link to comment https://forums.phpfreaks.com/topic/105528-solved-convert/#findComment-540951 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) Link to comment https://forums.phpfreaks.com/topic/105528-solved-convert/#findComment-540986 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. Link to comment https://forums.phpfreaks.com/topic/105528-solved-convert/#findComment-541026 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. Link to comment https://forums.phpfreaks.com/topic/105528-solved-convert/#findComment-541039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.