开发者

How go get entry from last year MySQL

This part of the query doesn't seem to be working

$iThisY开发者_StackOverflowear = date('Y');
$iLastYear = $iThisYear-1;

SELECT * FROM `{$this->_sPrefix}clicks` 
WHERE `affiliate_id` = '{$iAid}' 
AND `raw` = '1' 
AND YEAR(`date`) = '{$iLastYear}'

It grabs from this year still. Does YEAR work?


Could you use DATE_SUB instead

SELECT * FROM `{$this->_sPrefix}clicks` 
WHERE `affiliate_id` = '{$iAid}' 
AND `raw` = '1' 
AND YEAR(`date`) = YEAR(DATE_SUB(CURDATE(), INTERVAL 1 YEAR))


Use DATE_SUB

.... where yourdate_column > DATE_SUB(now(), INTERVAL 12 MONTH)


date('Y') returns a string. You might be running into a problem trying to subtract 1 from a string. You should try subtracting a year's worth of seconds from your timestamp and get that Year. I could be wrong because I know php is loosely typed, and I can't get my xampp working atm to test it. Good luck bud


The following worked for me:

AND year = YEAR( NOW() ) - 1

Answering this for future reference.

Good luck!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜