C-u C-c ! generates a time stamp like [2015-05-04 Mon 17:13]

I would like to assign a shortcut (e.g F1) to this action.

So far I have:

(defun my/timenow (&optional arg) 
 (let ((current-prefix-arg 4)) ;; emulate C-u
 (org-time-stamp arg 'inactive)

But this prompts me for the time and I have to press RET to insert it.

How can I insert the inactive timestamp without any prompts at all?


From the documentation of org-time-stamp:

With two universal prefix arguments, insert an active timestamp with the current time without prompting the user.

So eval the below:

(org-time-stamp '(16) t)
  • '(4) - one prefix arg (4)
  • '(16) - two prefix args (4 * 4)
  • '(64) - three prefix args (4 * 4 * 4)

To read more about the universal arguments and arguments in general:

  • 2
    Bonus points for explaining the 4/16/64 notion of prefix args ^_^. Thank you. – Leo Ufimtsev May 5 '15 at 14:01
  • This command (insert (org-time-stamp '(16) t)) inserts two timestamps next to each other. Do you know why? – miguelmorin Oct 15 '18 at 15:42
  • 1
    @mmorin if you look at org-time-stamp code (use M-x find-function), it's inserting by itself, so you don't need extra insert. Alternatively, you can use insert with a combination of format-time-string and org-time-stamp-format. – karlicoss Feb 15 '19 at 23:37
  • One interesting thing I noticed is that org-time-stamp requires an argument to be called since it's (defun org-time-stamp (arg &optional inactive) ...). I wonder what argument is actually passed in when you press C-c .. I was not able to simulate that programatically. – xji Mar 26 '20 at 9:46

Now there is a dedicated function for this (see org-time-stamp-inactive). For example:

(defun my/timenow ()
 (let ((current-prefix-arg '(16)))
   (call-interactively 'org-time-stamp-inactive)))

(define-key org-mode-map (kbd "<f1>") 'my/timenow)

You can also skip the prompt with two universal prefix arguments: C-u C-u C-c !.


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.