I would like to change the behavior of C-c C-x i so that it creates a "date created" timestamp i.e.

** TODO New Task
   CREATED: [2016-03-29 Tue 11:41]

I basically want to log the age of tasks, but I'm not interested in tracking the time spent on a task. Is there a strait forward way to do this?


Instead of adding it to the LOGBOOK, it might work better to add it a property. In particular, it's easier to get the created time out that way. This function sets a CREATED property with the current time in an inactive time stamp. It will not alter any existing CREATED property.

(defvar org-created-property-name "CREATED"
  "The name of the org-mode property that stores the creation date of the entry")

(defun org-set-created-property (&optional active NAME)
  "Set a property on the entry giving the creation time.

By default the property is called CREATED. If given the `NAME'
argument will be used instead. If the property already exists, it
will not be modified."
  (let* ((created (or NAME org-created-property-name))
         (fmt (if active "<%s>" "[%s]"))
         (now  (format fmt (format-time-string "%Y-%m-%d %a %H:%M"))))
    (unless (org-entry-get (point) created nil)
      (org-set-property created now))))

If you're using org-capture to create entries, you can call this automatically by adding it to a hook: (add-hook 'org-capture-before-finalize-hook #'org-set-created-property)

  • I'm a little confused how this works. How would creating a task trigger creating a timestamp item in :PROPERTIES:? – Tom Mar 29 '16 at 23:36
  • It triggers automatically when you create an entry using org-capture (C-c c). Otherwise you can call it manually or hook into whatever functions is creating your entry. – erikstokes Mar 29 '16 at 23:50
  • Interesting, I didn't know about org-capture it seems very powerful. – Tom Mar 30 '16 at 15:57

You can accomplish this by tracking TODO state changes. Specifically, if you add a timestamp to the TODO

(setq org-todo-keywords
   '((sequence "TODO(t!)" "WAIT(w@/!)" "|" "DONE(d!)" "CANCELED(c@)")))

This will add timestamps (indicated by the !) when you create a new TODO, change it to WAIT, or change it to DONE. See the linked manual page for more details.

To get this timestamp entered into your LOGBOOK drawer, you need to set the variable org-log-into-drawer to t (or the name you want to use for the drawer if it isn't "LOGBOOK").

This will produce the following:

** TODO My Task
   - State "TODO"       from "NEW"        [2016-01-18 Mon 13:36]
   Update stackexchange answer

I think this is the closest you can get to the requested CREATED: timestamp using orgmodes built-in features. To further change the formatting would require some custom elisp I think.

  • Doing that results in something that looks like this - State "TODO" from [2016-03-29 Tue 11:41] is there an easy way to insert this data into the :LOGBOOK: similar to the format I mention in my question? – Tom Mar 29 '16 at 17:00
  • Sorry, forgot which of the settings in my config applied to this issue. See the update. – Tyler Mar 29 '16 at 17:22
  • What do you have C-c C-x i bound to, by the way? – Tyler Mar 29 '16 at 17:27
  • C-c C-x TAB runs the command org-clock-in, which is an interactive autoloaded Lisp closure in `org-clock.el'. – Tom Mar 29 '16 at 18:25
  • Is there a way to change the format of the item on the log book from - State "TODO" from "NEW" [2016-01-18 Mon 13:36] to simply [2016-01-18 Mon 13:36]? Also how can I map this functionality to a key combination? – Tom Mar 30 '16 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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