how do we go about fetching records from 'Last Month'?
select count(*)
from xf_post p, xf_thread t
where p.thread_id=t.thread_id and
t.node_id=[id of the forum in question] and
p.post_date between DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01 00:00:00') AND DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d 23:59:59')
SELECT user.username, COUNT(articles.thread_id) AS article_countFROM xf_user AS user
INNER JOIN xf_user_profile AS user_profile
ON (user.user_id = user_profile.user_id)
INNER JOIN ewrporta2_catlinks AS catlinks
ON (catlinks.user_id = user.user_id)
INNER JOIN ewrporta2_articles AS articles
ON (articles.thread_id = catlinks.thread_id)
WHERE MONTH(CURDATE() articles.article_date between DATE_FORMAT(NOW() - INTERVAL 1 MONTH,'%Y-%m-01 00:00:00') AND DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d 23:59:59')
GROUP BY user.user_id
Ahh, forgot that XF stores dates as integers and not datetime. Change to;It's not working.
[...]
where articles.article_date between UNIX_TIMESTAMP(DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01 00:00:00')) AND UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d 23:59:59'));
Tried that and XenForo shows following error -Ahh, forgot that XF stores dates as integers and not datetime. Change to;
Code:[...] where articles.article_date between UNIX_TIMESTAMP(DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01 00:00:00')) AND UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d 23:59:59'));
public function getAuthorWithPostCount()
{
return $this->_getDb()->fetchPairs('
SELECT user.username, COUNT(articles.thread_id) AS article_countFROM xf_user AS user
INNER JOIN xf_user_profile as user_profile
ON (user.user_id = user_profile.user_id)
INNER JOIN EWRporta2_catlinks AS catlinks
ON (catlinks.user_id = user.user_id)
INNER JOIN EWRporta2_articles AS articles
ON (articles.thread_id = catlinks.thread_id)
WHERE articles.article_date BETWEEN UNIX_TIMESTAMP(DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-01 00:00:00')) AND UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), '%Y-%m-%d 23:59:59'))
GROUP BY user.user_id
');
}
WHERE articles.article_date BETWEEN UNIX_TIMESTAMP(DATE_FORMAT(NOW() - INTERVAL 1 MONTH, \'%Y-%m-01 00:00:00\')) AND UNIX_TIMESTAMP(DATE_FORMAT(LAST_DAY(NOW() - INTERVAL 1 MONTH), \'%Y-%m-%d 23:59:59\'))
We use essential cookies to make this site work, and optional cookies to enhance your experience.