Add CREATED date property to TODOs in org-mode

Renke Grunwald picture Renke Grunwald · Sep 4, 2012 · Viewed 7k times · Source

I read the org-mode manual but couldn't find an easy way to add a CREATED field to newly created TODOs. In combination with org-log-done one could then compute the time it took to close a particular TODO. This is especially useful when using archive files.

Example:

* TODO Do something
  CREATED:  [2012-09-02 Sun 23:02]
* DONE Do something else
  CREATED: [2012-09-02 Sun 20:02]
  CLOSED: [2012-09-02 Sun 22:02]

I would expect the CREATED field to be added to new tasks (tasks which don't have that field) whenever the file is saved.

Any suggestions on how to achieve this? Using something like Git is not a solution for me to track the creations of TODOS.

Answer

mrb picture mrb · Nov 8, 2012

I use org-expiry to implement that functionality, which is in the contrib directory of org.

The base configuration I use is:

;; Allow automatically handing of created/expired meta data.
(require 'org-expiry)
;; Configure it a bit to my liking
(setq
  org-expiry-created-property-name "CREATED" ; Name of property when an item is created
  org-expiry-inactive-timestamps   t         ; Don't have everything in the agenda view
)

(defun mrb/insert-created-timestamp()
  "Insert a CREATED property using org-expiry.el for TODO entries"
  (org-expiry-insert-created)
  (org-back-to-heading)
  (org-end-of-line)
  (insert " ")
)

;; Whenever a TODO entry is created, I want a timestamp
;; Advice org-insert-todo-heading to insert a created timestamp using org-expiry
(defadvice org-insert-todo-heading (after mrb/created-timestamp-advice activate)
  "Insert a CREATED property using org-expiry.el for TODO entries"
  (mrb/insert-created-timestamp)
)
;; Make it active
(ad-activate 'org-insert-todo-heading)

If you are using capture it does not automatically work and needs a little glue. I have posted the complete config here: https://gist.github.com/4037694