I know this is an old question, but I was trying to do the same thing and ended cooking something up. So I might as well share.
Since there doesn't seem to be anything of the sort available out of the box, we need a custom sort function and thus also to set an entry in org-agenda-custom-commands
so as to be able to set proper sorting. For an custom-commands entry like:
("n" "Whatever"
((tags "CLOSED<=\"<now>\""))
((org-agenda-cmp-user-defined 'org-cmp-closed)
(org-agenda-sorting-strategy '(user-defined-down))))
We define the corresponding sort function as:
(defun org-cmp-closed (a b)
(let* ((a-marker (get-text-property 0 'org-marker a))
(b-marker (get-text-property 0 'org-marker b))
(now (current-time))
(a-closed-ts (org-timestamp-from-string
(org-entry-get a-marker "CLOSED")))
(b-closed-ts (org-timestamp-from-string
(org-entry-get b-marker "CLOSED")))
(a-closed-time (or (and a-closed-ts
(org-timestamp-to-time a-closed-ts))
now))
(b-closed-time (or (and b-closed-ts
(org-timestamp-to-time b-closed-ts))
now)))
(cond ((time-less-p b-closed-time a-closed-time) +1)
((time-less-p a-closed-time b-closed-time) -1)
(t nil))))
[ts]
and<ts>
see Inactive timestamp.[ts]
) do not contribute to the agenda, whereas active timestamps (<ts>
) do.