Mave
Active member
I've been using this query for years to get the number of posts made by myself in the past 365 days. It works great:
However I want to know how many posts were made in THIS year, so I modified the code to:
But sadly this isn't working.
I've also tried
I do get this error:
Fatal error: Uncaught Error: Call to a member function fetchColumn() on bool in -redacted- 146 Stack trace: #0 -redacted-(238): thisyeardate() #1 {main} thrown in -redacted- on line 146
Line 146 =
Any idea what's wrong? Help would be greatly appreciated!
Code:
$res = $db->query('
SELECT COUNT(*) AS total
FROM xf_post AS post
WHERE user_id = 1
AND (post.post_date >= UNIX_TIMESTAMP(CURDATE() - INTERVAL 8760 HOUR))
');
$num_rows = $res->fetchColumn();
echo $num_rows;
However I want to know how many posts were made in THIS year, so I modified the code to:
Code:
$res = $db->query("
SELECT COUNT(*) AS total
FROM xf_post AS post
WHERE user_id = 1
AND (post.post_date > Convert(datetime, '2023/01/01'))
");
$num_rows = $res->fetchColumn();
echo $num_rows;
But sadly this isn't working.
I've also tried
post.post_date >= '2023-01-01'
but that also wasn't working.I do get this error:
Fatal error: Uncaught Error: Call to a member function fetchColumn() on bool in -redacted- 146 Stack trace: #0 -redacted-(238): thisyeardate() #1 {main} thrown in -redacted- on line 146
Line 146 =
$num_rows = $res->fetchColumn();
Any idea what's wrong? Help would be greatly appreciated!
Last edited: