KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Date-based Filter Function not Working as Expected #1585

Closed The O opened this topic on on Aug 19, 2020 - 3 comments

The O commented on Aug 19, 2020

This code works and returns 148 records from my DB:


$current_date = '2020-08-19';
DataTables::create(
	array(
	"dataSource"=>$report->dataStore("tbl")
	 ->filter(function($row){							
	     return ($row["Date"] == '2020-08-19');
         })
)); 

When replace the date within the filter function with $current_date, it returns zero records.

What is the right way to do this?

David Winterburn commented on Aug 20, 2020

Hi,

You are comparing date strings so their format should be exactly the same. I would suggest print out both current date and $row['Date'] to see if their formatted values are the same. Thanks!

The O commented on Aug 20, 2020

I'm already printing out the records with a DataTable. When a literal '2020-08-19' is used, I can see the Date column has dates in the format '2020-08-19', which is exactly how it is in my DB.

Except Koolreport's in memory storage of dates differs from how a DataTable represents it (or how it read it off the DB for that matter.) Please confirm.

The O commented on Aug 20, 2020

Solution here applies.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

None