My config (spacemacs with ~0 extra) sets a CLOSED time when I move a task in org-mode to DONE:

***** DONE A task
CLOSED: [2022-09-12 Mon 16:18] SCHEDULED: <2022-09-07 Wed>

It's easy to only show DONE tasks, but now I'd like to get an agenda view that can use the timestamp set for CLOSED so that I can look back at what items I've finished in the past week. What can I do to build this?

I'm a beginner at this so I'm probably missing some basics. For instance I don't know what the difference is between a [timestamp] and a <timestamp>.

  • For the difference between [ts] and <ts> see Inactive timestamp.
    – NickD
    Sep 13, 2022 at 17:34
  • Inactive timestamps ([ts]) do not contribute to the agenda, whereas active timestamps (<ts>) do.
    – NickD
    Jul 11, 2023 at 2:10

2 Answers 2


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))
         (b-closed-time (or (and b-closed-ts
                                 (org-timestamp-to-time b-closed-ts))
    (cond ((time-less-p b-closed-time a-closed-time) +1)
          ((time-less-p a-closed-time b-closed-time) -1)
          (t nil))))

In the agenda dispatcher view (i.e. after C-c a if you have customized the setting as the manual suggests - or after M-x org-agenda), select m for a query to match tags/properties/todo and specify the following entry:


That should give you a list of DONE items that were CLOSED in the past week. I don't think it's sorted though and I don't remember how to sort that view (or even if it is possible). Untested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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