Jump to content

Help with unix time query


bsamson

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.