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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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