0

I'm trying to create an org-capture template that contains dates relative to the value of %t. I understand that with C-1 I can prompt for a particular date, and I'm looking for the day prior and the Friday after. I got this far, but now it seems to take today's date, not the particular date selected in the org-capture modal:

(org-read-date nil nil "-1" nil (org-time-string-to-time "%t"))
(org-read-date nil nil "+fri" nil (org-time-string-to-time "%t"))

I also struggled with the "+fri", which seems to return the Friday after the date. I was hoping to have the particular date if that particular date is a Friday.

4
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Commented Jul 11, 2022 at 1:39
  • What you are asking is unclear to me: in a capture template, %t is either replaced by the current time (if you call org-capture) or it is replaced by whatever time stamp is at point in the current buffer (if you call org-agenda-capture). AFAICT, there is no prompting, i.e. you cannot enter a time interactively.
    – NickD
    Commented Jul 11, 2022 at 14:04
  • I guess what you want is %^t - however, filling in values interactively is the last step in template expansion, so I don't think you can get the value, manipulate it and insert it back into the template for further expansion. It may be possible through lisp expressions in the template, but the whole thing seems fragile to me. An example of what exactly you are trying to accomplish (i.e. an example of an entry that the capture template is supposed to create) would go a long way towards clarifying the question and possibly enabling either a solution or suggestions for another way.
    – NickD
    Commented Jul 11, 2022 at 15:34
  • Thanks. I had understood that :time-prompt would allow me to prompt for a datetime other than use the current or the datetime at point. The below answer comes very close to what I was looking for. Thank you again!
    – wslt
    Commented Jul 12, 2022 at 0:15

1 Answer 1

0

This may not be exactly what you are looking for but it is what I used to specify a date two days in the future. It took me quite a while to figure this out (not an elisp expert)

; excerpt from capture template

;; technique to set deadline relative to today's date

;;      DEADLINE: %(org-insert-time-stamp (org-read-date nil t \"+2\"))

Got the idea from one of Sacha Chua's posts.

2
  • This is awesome. Thank you so much. I'd been struggling with this based on SC's post here. I tried to build an if statement that would return t if t is a Friday and (org-insert-time-stamp (org-read-date nil t "+fri")) if not. Is this within the realm of the possible?
    – wslt
    Commented Jul 12, 2022 at 0:13
  • org-read-date is an internal org-mode function, and as such is documented mostly indirectly. Sorry, this is the limit of my expertise, but you can always try emailing Sacha, she is likely to answer.
    – ian
    Commented Jul 13, 2022 at 1:19

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.