DB READ - BETWEEN TWO DATES (V5)

Filter database records between two dates in ChronoForms.

Overview

The issue was caused by incorrect PHP array syntax and improper date formatting in the DB Read action.
Use a single array element with a custom SQL condition that includes the BETWEEN operator and ensure dates are in the correct MySQL format.

Answered
ChronoForms v5
at atanunu 18 Feb, 2017
I need the DB Read action to get records between two dates, I am having issues making this work. Kindly help

NORMAL SQL QUERY
"WHERE Payment = 1 AND id = '$a' AND Date BETWEEN '$b' AND '$c'";


I need to implement the code above in array format below:

RETURN ARRAY AS REQUIRED BY DB READ ACTION

return array(
        'Payment' => 1,
        'id' => $form->data['pcuser'],
  	'PWVTransactionDate >= ' => $form->data['pcfromactual'],
  	'PWVTransactionDate <= ' <= $form->data['pctoactual'],
);
?>


I will be very grateful
Max_admin Max_admin 18 Feb, 2017
Hi atanunu,

The last line in the array is wrong, it should be => like the others, this is php array syntax.

The date supplied should be in the mysql format too, try this:

date("Y-m-d H:i:s", strtotime($form->data["date_field"]))


Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
at atanunu 18 Feb, 2017
Thanks sir, the date is formatted as required and as contained in the MySQL table.

I have attached a screen shot of the table with out conditions and my error should be properly using the
BETWEEN '2005-01-01 00:00:00 AM' AND '2017-02-19 00:00:00 AM'
In the return array
Gr GreyHead 18 Feb, 2017
Answer
Hi atanunu,

Please try
<?php
return array( ": `Payment` = 1 AND ( `PWVTransactionDate` BETWEEN '{$form->data['pcfromactual']}' AND '{$form->data['pctoactual']}' )" );
?>

Bob
at atanunu 18 Feb, 2017
Thanks Sir,

You are amazing! the solution was awesome and works exactly as I needed.
This topic is locked and no more replies can be posted.