# Can the format of a timestamp in an org-mode document be locally adjusted for export?

I have an org document:

#+Title: Birthdays of The Beatles

John Lennon was born on <1940-10-09 Mon>.

Each member of the Beatles had a birthday.

| Beatle          | Birthday         |
|-----------------+------------------|
| John Lennon     | <1940-10-09 Mon> |
| Paul McCartney  | <1942-06-18 Thu> |
| George Harrison | <1943-02-25 Thu> |
| Ringo Starr     | <1940-07-07 Sun> |


which exports to ascii as

               __________________________

BIRTHDAYS OF THE BEATLES

Me
__________________________

John Lennon was born on <1940-10-09 Wed>.

Each member of the Beatles had a birthday.

Beatle           Birthday
-----------------------------------
John Lennon      <1940-10-09 Wed>
Paul McCartney   <1942-06-18 Thu>
George Harrison  <1943-02-25 Thu>
Ringo Starr      <1940-07-07 Sun>


I want to alter the formats of the dates so that the dates in the body and the dates in the table are different:

               __________________________

BIRTHDAYS OF THE BEATLES

Me
__________________________

John Lennon was born on <Wed Oct-09 1940>.

Each member of the Beatles had a birthday.

Beatle           Birthday
-----------------------------------
John Lennon      <Oct-09>
Paul McCartney   <Jun-18>
George Harrison  <Feb-25>
Ringo Starr      <Jul-07>


Is this possible?

What happens to timestamps when you export to ASCII is determined by the function org-ascii-timestamp (likewise org-latex-timestamp for Latex export and so on). You just have to redefine that to make them export to whatever you like. Here we use org-read-date to convert the timestamp to an internal time and format-time-string to format the time in whatever way we like:

(defun org-ascii-timestamp (timestamp _contents info)
(format-time-string
"<%b-%d>"


Unfortunately, this will alter the timestamps for /all/ ASCII exports, not just this document. To make it truly document local, you would have to redefine the export function to something like

(defun org-ascii-timestamp (timestamp contents info)
(funcall org-ascii-timestamp-function (timestamp contents info))


and set org-ascii-timestamp-function to be a function with the current definition of org-ascii-timestamp. Then you could use #+BIND to change the definition locally. This is a bit of a hack and also affects the whole document.

What we really want is to set a property (say TIMESTAMP_FMT) and have it apply only to that subtree. It is somewhat difficult to lookup properties during export, but it can be done:

(defvar org-ascii-timestamp-format "<%Y-%m-%d %a>")

(defun org-ascii-timestamp (timestamp _contents info)
(let ((org-ascii-timestamp-format
(or (org-entry-get (plist-get (car (cdr timestamp)) :begin)
"TIMESTAMP_FMT")
org-ascii-timestamp-format)))
(format-time-string
org-ascii-timestamp-format

This makes the timestamp format local to a tree (it can be inherited or not depending on how you set org-use-property-inheritance). I don't know a way to make a property local to a table.
• Also in "modern" org-mode (>=9.0) the org-timestamp-translate function uses the variable org-time-stamp-custom-formats, so you don't have to redefine the org-ascii-timestamp function; just the variable (I think, but I did not test). But it still would affect both the text and table timestamps. – NickD May 23 '17 at 0:21
• @Nick I hadn't been aware of org-time-stamp-custom-formats. It almost does the right thing, but I don't see a way of modifying it locally short of redefining the function as above. – erikstokes May 24 '17 at 0:03