KoolReport's Forum

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

DateRangePicker and filter excluding first date #3015

Open paulo opened this topic on on Mar 21, 2023 - 7 comments

paulo commented on Mar 21, 2023

Hi there, I am not sure if I am doing something wrong here, but it seems the DateRangePicker with filter is excluding the first record with the first date.
Here is my DatePicker: DateRangePicker::create(array(

                "name" => "dateRange",
                "icon"=>true
            ));

When it sends/loads , it sends this to the report: start=2023-04-01 00:00:00 end=2023-04-30 23:59:59

Report has a query with filter:

 ORDER BY T.startDate")
            ->pipe(new Filter(array(
                array("startDate",">=",$this->params["dateRange"][0]),
                array("startDate","<=",$this->params["dateRange"][1])
            )))

I look at the database which contains records with startDate='2023-04-01'

When I select using the date picker April 1st to April 30th, it sends the following start=2023-04-01 00:00:00 end=2023-04-30 23:59:59 but all records with startDate='2023-04-01' are excluded.

When I change the date picker to March 31st, to April 30th, it sends the following to the server, and it includes all April 1st results startDate='2023-04-01'. this start=2023-03-31 00:00:00 end=2023-04-30 23:59:59

However, my filter says >= array("startDate",">=",$this->params["dateRange"][0]), so I shouldn't have to select March 31 to include April 1st records, correct?

thank you Paulo

AhmedHaroon commented on Mar 22, 2023

@Paulo have you checked without using this Filter ?

i am a very beginner to KoolReport and CodeIgniter, not yet used this Filter as you did and not faced the said problem. ( may be i overlooked, will check again thoroughly ). i am using it in WHERE clause of my SELECT query.

OR i misunderstood?

regards

paulo commented on Mar 22, 2023

thanks - when I change I get the following error. The filter should work, and/or the DatePicker should return only a date. I am not sure what is going on here, I believe it used to work: thanks SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2023-04-01 00:00:00'' AND T.startDate<=''2023-04-30 23:59:59'' ORDER BY T.startD' at line 29

AhmedHaroon commented on Mar 24, 2023

@paulo

i can't say anything else as per my very beginner level knowledge (mentioned earlier), seniors here can help when they have time.

David Winterburn commented on Apr 3, 2023

@paulo, sorry for the late reply. May I ask whether your "startDate" field is of date or datetime type?

paulo commented on Apr 3, 2023

np. Thanks for replying. It is date only. I changed the query to use the comparison on where instead of like this T.startDate >=DATE('".$this->params["dateRange"][0]."') it seems to have fixed the problem... but filter should work too, correct? thanks

David Winterburn commented on Apr 4, 2023

Yes, you can also use the Filter process but try removing the time part of the date range like this:

            ->pipe(new Filter(array(
                array("startDate",">=", date('Y-m-d', strtotime( $this->params["dateRange"][0] ))),
                array("startDate","<=", date('Y-m-d', strtotime( $this->params["dateRange"][1] )))
            )))

Let me know if this works for you. Thanks!

paulo commented on Apr 4, 2023

thank you

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
bug
solved

None