Forums

Where php query between now and -1 year

Twincarb 30 Aug, 2017
I have a CC6 view used to show records from the db, I would like to narrow the records shown by showing only records created in the last year. Having searched the forum I found a snippet of code that I expected to work and modified it.

This is in my where condition

<?php
$oneYearAgo = date("Y-m-d H:i:s", strtotime("-1 year"));
$now = date("Y-m-d H:i:s", strtotime("now"));

return array(":gmp.created between $oneYearAgo and $now");
?>


The result it returns is an error message:

1054 - Unknown column ':gmp.created between 2016-08-30 19:34:55 and 2017-08-30 19:34:55' in 'where clause'


gmp is my model name and created is the column name, the column is listed under "Fields to retrieve" but I am still returning the error above. I have cleared the database cache but am now stuck!

Thanks in Advance

Dave
Max_admin 31 Aug, 2017
Answer
Hi Dave,

The syntax for v6 is different, please try the following:

<?php
$oneYearAgo = date("Y-m-d H:i:s", strtotime("-1 year"));
$now = date("Y-m-d H:i:s", strtotime("now"));

return [["gmp.created", $oneYearAgo, ">"], "AND", ["gmp.created", $now, "<"]];
?>


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Twincarb 31 Aug, 2017
1 Likes
Thanks for the answer Max

Regards,

Dave
This topic is locked and no more replies can be posted.