Forums

filter by range of dates

ak613 23 Jul, 2015
Hi,
I read the post filtering by a range of results and this FAQ and am therefore trying to use

<?php
if(\GCore\Libs\Request::data("datemin")){
return array("view_Docs.DATEIN >=" => \GCore\Libs\Request::data("datemin");}
if(\GCore\Libs\Request::data("datemax")){
return array("view_Docs.DATEIN <=" => \GCore\Libs\Request::data("datemax"));}
?>


to filter by a range of dates. However, nothing happens when I fill in the datemin or datemax fields and submit. (This is in the conditions box under models, and the fields code is in the footer.) I'm wondering if this has to do with the fact that the field I'm comparing to (view_Docs.DATEIN) is a timestamp in the database. I convert it to a date using
view_Docs.DATEIN:return date('m/d/Y', strtotime($cell));

in the php functions box under Front List.

I've tried everything I can think of to change \GCore\Libs\Request::data("datemin") to the same format as view_Docs.DATEIN so they'll compare correctly, but no matter what I do, it's as if there is no condition at all.

Is there a way to fix it so the comparison works?
Any advice is appreciated!!

Thanks,
AK
ak613 03 Aug, 2015
So I'm feeling kind of frustrated here...

Please can someone help me????

Thank you!
AK
krondor 06 Feb, 2016
Hello. You can add date convertation code

date('m/d/Y', strtotime($cell));

in conditions box under models and it'll work.
GreyHead 21 Feb, 2016
Hi,

kondor is correct here - a MySQL database query can only compare dates in yyyy-mm-dd format, If you try with any other format you are doing string comparisons and will get unpredictable results.

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