bsamson Posted October 17, 2009 Share Posted October 17, 2009 Hello. I am trying to create a query to show all result within 2 months ... Here's the query: $query = "SELECT * FROM v2callbacks WHERE store='96' AND (DATE_FORMAT(FROM_UNIXTIME(`cbdate`), '%Y/%m') = '2009/10') AND (DATE_FORMAT(FROM_UNIXTIME(`cbdate`), '%Y/%m') = '2009/11') AND cbstatus != 'c' ORDER BY lname ASC" or die(mysql_error()); I just added the second DATE_FORMAT ... and now it shows 0 results. Anyone have any suggestions what the problem is ... or if there is a better way to do this. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/178029-help-with-unix-time-query/ Share on other sites More sharing options...
DavidAM Posted October 17, 2009 Share Posted October 17, 2009 AND (DATE_FORMAT(FROM_UNIXTIME(`cbdate`), '%Y/%m') = '2009/10') AND (DATE_FORMAT(FROM_UNIXTIME(`cbdate`), '%Y/%m') = '2009/11') AND The column cannot be BOTH October AND November. I think you meant to use OR AND ( (DATE_FORMAT(FROM_UNIXTIME(`cbdate`), '%Y/%m') = '2009/10') OR (DATE_FORMAT(FROM_UNIXTIME(`cbdate`), '%Y/%m') = '2009/11') ) AND Also added a set of parenthesis around the two DATE_FORMAT tests since the OR would otherwise breakup the condition. By the way, is cbdate actually stored as a unix timestamp? If you used a mySql DateTime column, this is not the correct way to query it. Link to comment https://forums.phpfreaks.com/topic/178029-help-with-unix-time-query/#findComment-938758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.