Create a views "exposed filter" to compare two fields First of all: 

I know that there's a static filter with Global: Fields comparison that would do it. But I need an exposed filter in views to fullfill my needs.

Let's say I have a table with 3 cols: "nid" | "changed" | "another datetime".

Now I want to have an exposed filter as a select list with options "none", "old" and "new".
If "old" is selected, show rows where "another datetime" > "changed".
If "new" is selected, show rows where "another datetime" &lt; "changed".

I've been looking for a solution for multiple hours.
Solution 1

Make use of views php to do the compare with the help of https://www.drupal.org/project/views_php

In that case you have to write some code which is executed on each row, in the end it will work but it is very bad in maintaining. You do not have any integrated editor for error code checking etc etc. It is a solution but I do not recommend it.

Solution 2

Make use of the hook views_post_execute with parameter of the view name.

function YOURMODULENAME_views_post_execute(&amp;$view){

For easy maintenance start with a switch

switch ($view-&gt;name){

    case "YOURVIEWNAMEA";
    case "YOURVIEWNAMEB";
    case "YOURCASEVIEW";

    foreach ($view-&gt;result as $row =&gt; $rowinfo) {


      // put here your code to do something with each result.

       // E.G Delete a value in the result of the view making use of unset statement 
        unset ($view-&gt;result[$row]);


      }