I am trying to filter my view by using a date range so that it shows all the activities at an event:

Activity Start >= Event End & Activity End <= Event Start

To do this I have set up a view to show all Activities with a contextual filter to allow the Event dates to be accessed.

I added the 4 fields to my table: Activity Start, Activity End, Event Start and Event End.

My $Row data when adding a Global:php filter criteria now has the four variables accessible to carry out the comparison above:

Activity Start: $Row->field_start_date_and_time Activity End: $Row->field_start_date_and_time_1 Event Start: $Row->field_start_date_and_time_2 Event End: $Row->field_start_date_and_time_3

I am using views_php 7.x-2.x-dev - which fixed the issue of $row not populating.

I am trying to write the above comparison in php and am not getting results as expected (i thought this would be the easy bit, I have spent a long time getting this far).

However, it appears that the date format is not being read correctly as it is not returning any results - I have done some research which would indicate it might need to be in unix timecode to do the comparison accurately.

Is this correct? What does the code look like to do it?

Any suggestions greatly appreciated.


You really shouldn't use PHP in Views have you seen the warning on the module page:

While this module allows you to directly use PHP inside views which may be useful for quick and easy solutions, it is highly advisable to use regular handlers and plugins when available (or even to create one yourself). Take note that filtering and sorting a view using PHP always has a considerable performance impact.

Also this post has instructions how to write a Views handler or Plugin.

You should be able to achieve what you're trying to do with a combination of contextual filters, normal filters and relationships.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.