Date filter

monkframes

Member
Hi,

Is there any way to filter a date field in a dropdown to show only the list of dates but not times ?, as the date element stores date and time together, I can?t find the way to do it, for example:

I have a list of bookings, some of them for the same day but at different times:
2014-05-02 10:00:00 ... ... ...
2014-05-02 11:30:00 ... ... ...
2014-05-02 23:15:00 ... ... ...
2014-05-05 09:00:00 ... ... ...
2015-05-07 12:00:00 ... ... ...

I need to have a dropdown filter to show:
2014-05-02
2014-05-05
2015-05-07

And if I choose 2014-05-02, the list must display only the bookings of that day ordered by time:
10:00:00 ... ... ...
11:30:00 ... ... ...
23:15:00 ... ... ...

Any clue ???

Thanks in advance.
 
In the Date element go to the tab titled "Date Formats".

If you are seeing date and time in your lists then you probably have an entry such as "Y-m-d H:i:s" within the field that says "List Format". Simply change this to "Y-m-d", or whatever layout you need, and you will see date only and the filters will become the same.

I believe if you place a sort on that element, i.e List->Data->OrderBy, they should be in Date and Time order.
 
Thanks felixkat, actually I did it, but as the data is date+time the result in my example is 3 times the date 2014-05-02, so that means the format is applied just as a mask but the filter takes the hole data including the time ....
 
Oh I think I see what you mean. You want to display only one date entry but if there are three times for that days it will show three times.

Have you considered splitting them up, i.e having a date element and a time element? This would be the easiest way because if you filter on the date you will see just the "time" entries which I think is what you want.
 
Yes I did it that way before, but I need to validate dates ir order to not to allow changes if less than 12 hours to the booking time, so having date and time in a single datetime field is better to validate .... but not to filter ....

The only way I was thinking on is having a datetime field for the form and validation that, onChange, copies the date to a date field used to filter and the time to a time field displayed in the list .... I would prefer not to duplicate data but if there?s not a better option ....
 
I?m still working on it .... I want to validate each element, I started using the following validation code in the form-complements-php onBeforeProcess, but I change my mind:

$date1 = your time field;
$date2 = time();
$subTime = $date1 - $date2;
$y = ($subTime/(60*60*24*365));
$d = ($subTime/(60*60*24))%365;
$h = ($subTime/(60*60))%24;
$m = ($subTime/60)%60;
echo "The difference between ".date('Y-m-d H:i:s',$date1)." and ".date('Y-m-d H:i:s',$date2)." is:\n";
echo $y." years\n";
echo $d." days\n";
echo $h." hours\n";
echo $m." minutes\n";
if ($y < 1 and $d < 1 and $h < 12) { //if <12 hours to the booking time
echo "NOT ALLOWED\n";
}
else {
echo "ALLOWED\n";
}
exit;

Of course the purpose of this code is to check that it works, remove all de "echoes" and the "exit;" and substitute the if sentence with "return ($y < 1 and $d < 1 and $h < 12)" to do the validation.
 
What version of PHP do you have? There are much easier ways of doing date calculations, especially if your have PHP 5.4 or greater.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top