0

I am editing an old text file that has each entry preceded by a date = 11/23/1983. I would like to reformat this date to a org timestamp. Using the various methods specified in the documentation is very cumbersome when the year is far removed from the current date.

I tried creating a date then editing it using the method described in the documentation pasted below.

‘S- (org-timestamp-up)’ ‘S- (org-timestamp-down-down)’ Change the item under the cursor in a timestamp. The cursor can be on a year, month, day, hour or minute. ....

I can not get this method to work. I created a timestamp using the current date and then tried to edit as specified above. I can not put the cursor on the year, it is limited to the month field and will not allow me to put the cursor on any other field.

So what is the best way to enter a timestamp for say 11/23/1983? There are many edits to be made so I need a simple and quick method.

Oh, I also tried just typing the date like 11/23/1983 and putting brackets around it [12/23/1983] hoping it would accept that as a timestamp but that hack failed.

Any suggestions/guidance appreciated.

1
  • You can cut-and-paste something like 11/12/99 into the date prompt of C-c . and it will DTRT.
    – NickD
    Commented Apr 4, 2022 at 18:49

2 Answers 2

0

When org-mode is on default settings:

not valid <2017/08/24>
valid [2017-08-24 Thu]
valid <2017-08-24 Thu>

C-c . runs the command org-time-stamp (found in org-mode-map), which is an interactive compiled Lisp function in ‘org.el’.

If your file had time stamps already, I would sujest to reformat them with regex search and replace.

Links

2
  • The current format of the dates is just a plain date ie: 23/10/86 without any brackets etc. Some are formatted like 5/6/99. So they are just text, not conforming to org timestamp format. I tried manually adding brackets (ie: [23/10/99] but the result was not interpreted as timestamps by org. Since this is a one time process, I think I will just manually add each one. Probably easier than trying to solve the problem. My org-mod skills are limited. Thanks for the reply.
    – RonG
    Commented Aug 26, 2017 at 15:13
  • @RonG check this answer: emacs.stackexchange.com/questions/19863/…
    – Hellseher
    Commented Aug 28, 2017 at 19:12
0

You can convert all non-Org dates in the current buffer to well-formed active or inactive Org time stamps using something like the following:

(defvar my-orgify-date-format
  (rx bow (** 1 2 digit) ?/ (** 1 2 digit) ?/ (= 2 digit) (? (= 2 digit)) eow)
  "Regexp matching dates to transliterate to Org time stamps.
Used by `my-orgify-dates'.")

(defun my-orgify-dates (&optional start end inactive)
  "Transliterate dates in region to Org time stamps.
START and END delimit the region and default to the bounds of the
accessible portion of the buffer.  If prefix argument INACTIVE is
non-nil, use square, rather than angular, Org time stamp
brackets, so as not to contribute to the agenda.  The regexp
`my-orgify-date-format' determines which dates to transliterate."
  ;; This function is adapted from `delete-trailing-whitespace'
  (interactive (let ((region (use-region-p)))
                 (barf-if-buffer-read-only)
                 (list (and region (region-beginning))
                       (and region (region-end))
                       current-prefix-arg)))
  (require 'org)
  (save-match-data
    (save-excursion
      (goto-char (or start (point-min)))
      (let ((end-marker (if end (copy-marker end) (point-max-marker))))
        (while (and (< (point) end-marker)
                    (re-search-forward my-orgify-date-format end-marker t))
          (org-insert-time-stamp (org-read-date nil t (delete-and-extract-region
                                                       (match-beginning 0)
                                                       (point)))
                                 nil inactive))
        (set-marker end-marker nil)))))

This defines a command my-orgify-dates, which does the work, as well as a variable my-orgify-date-format, which allows you to tweak which dates get converted.

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.