Rewrite date filtering logic