Org-time-stamp only gives date - no time (hours:minutes:seconds)

What happened?

I am trying to add timestamp to the document. I don’t know how to change it so that it gives time as well, or just time.

image

generated  Oct 08, 2022 12:49:01
system     Ubuntu 22.04.1 LTS Linux 5.15.0-48-generic x86_64 x
emacs      28.1 ~/.emacs.d/
doom       3.0.0-pre PROFILE=_@0 HEAD -> master 57e99650 2022-10-03 18:33:28 +0200
           ~/.doom.d/
shell      /bin/bash
features   ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
           JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
           INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS X11
           XDBE XIM XPM XWIDGETS GTK3 ZLIB
traits     gui daemon server-running envvar-file custom-file
custom     package-selected-packages org-agenda-files
modules    :config use-package :completion company vertico :ui doom doom-dashboard
           doom-quit hl-todo modeline ophints (popup +defaults) vc-gutter
           vi-tilde-fringe workspaces :editor (evil +everywhere) file-templates fold
           multiple-cursors snippets word-wrap :emacs dired electric undo vc :term
           vterm :checkers syntax grammar :tools docker (eval +overlay) gist lookup
           lsp magit make pass pdf :lang clojure common-lisp csharp data emacs-lisp
           fortran json javascript latex markdown (org +pretty +journal +roam2 +hugo
           +brain +dragndrop +jupyter +noter +pandoc +present) (python +lsp +conda
           +cython +poetry) qt racket rest rust sh yaml :email (mu4e +org +gmail)
           notmuch (wanderlust +gmail) :app calendar everywhere irc twitter :config
           (default +bindings +smartparens)
packages   (nhexl-mode)

How are you creating a timestamp? M-x org-schedule? M-x org-deadline? M-x org-time-stamp? Some other way?

If you specify a time with any of the commands above, say Tomorrow at 3pm, it will produce a timestamp that includes a time like <2022-10-08 Sat 15:00>.

To make it always do so:

;;; add to $DOOMDIR/config.el
(after! org
  (setq org-time-stamp-formats '("<%Y-%m-%d %a %H:%M>" . "<%Y-%m-%d %a %H:%M>")))

Fantastic, thank you! I didn’t realise that you can add time by typing it in those commands’ dialogs/buffers. That makes sense now.

Thank you for the example of setting the variable, as well. I can imagine that would have tripped me later on.

Out of curiosity, one thing I couldn’t find is why the value is an alist ("<%Y-%m-%d %a %H:%M>" . "<%Y-%m-%d %a %H:%M>") and not just "<%Y-%m-%d %a %H:%M>", but maybe that’s irrelevant

You’re right, it’s not well documented. The Org codebase uses the first value as the “short” timestamp format (generally used when time is unspecified) and the second as the “long” one. All uses of the variable expect it to be a cons cell, so it cannot be set to a string.

1 Like

Please don’t do this. It is a constant and you are not supposed to change it. Consequences may be unpredicatable. Instead, just call org-time-stamp with prefix argument.

1 Like

Great explanation, thanks again!

Thanks for the heads up, I’m still a bit of a noob to emacs, can you please let me know how to

? Am I reading it right, that it’s a way to call the org-time-stamp command so that it could be formatted as <%Y-%m-%d %a %H:%M>

By typing SPC u (or C-u for non-evil users) before you invoke org-time-stamp. E.g. SPC u M-x org-time-stamp

SPC u / C-u = known as either the universal argument or prefix argument. Is commonly used to indicate to commands you want behavior different from the default. It’s up to the command how they’ll respond to them, but in org-time-stamp's case, it forwards the prefix arg to org-insert-time-stamp, which instructs it to return the long timestamp format.

Unfortunately, this doesn’t work the same way for org-schedule and org-deadline, but giving the calendar prompt a time component (e.g. “tomorrow at 3pm”) gets around that.

1 Like

Oh, that makes sense, thanks again. I realise that was a really basic question and really appreciate this detailed explanation.

I’ve commented out (setq org-time-stamp-formats '("<%Y-%m-%d %a %H:%M>" . "<%Y-%m-%d %a %H:%M>"))) from config.el and will try to use SPC-u SPC-u SPC-m-d-t instead.

May need to find a way to turn this into a separate function (e.g. org-time-stamp-with-time to avoid so many keystrokes later on.

Strangely enough I had to restart emacs daemon for the change to take effect - I thought that doom/reload would reload changes in config.el. Bearing in mind side effects @yantar92 mentioned I thought that’s a safer way though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.