Where php query between now and -1 year

Filter records from the last year in a ChronoForms v6 view.

Overview

The issue occurs because the WHERE condition uses an incorrect syntax for ChronoForms v6, causing a database error.
Use the correct v6 array syntax to specify the date range, ensuring the column name and comparison operators are properly formatted.

Answered
Connectivity v6
Tw 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 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.
This topic is locked and no more replies can be posted.