Select rows with repeat data within certain timeframe
how about this:

 SELECT t1.task_id, t1.reference
   FROM tasks t1
   JOIN tasks t2 
        ON t1.reference = t2.reference 
           AND abs(t1.end_date - t2.end_date) &lt; 30;


Note this assumes that end_date is a date, and not a timestamp.  If a timestamp cast to date first.