How can I create a time stamped file name with the org header arg:

#+export_file_name: <timestamp-var> + File name

There is a variable org-time-stamp, is there a way to append it to the static file name to create files with time stamp at time of export in the file name?


  • There is no such variable AFAIK. There is a function named org-time-stamp but that's a different kettle of fish. – NickD Mar 11 at 20:40

Add this to your init file:

(add-hook 'before-save-hook 'time-stamp)

and this to the Org file:

# Local Variables:
# time-stamp-format: "%04y-%02m-%02d_%f"
# time-stamp-pattern: "^#\\+export_file_name: %%$"
# End:

The value of #+export_file_name: should update every time the file is saved.

| improve this answer | |
  • Thanks! Doesn't work for me, not sure why! – Gaurav Mar 21 at 3:26
  • 1
    Make sure you (1) add the variables at the end of the file, and (2) kill and reopen the file (or M-x normal-mode) to set them. You also have to add #+export_file_name: nil near the top of the file (and start with some initial value or it won't work). – jagrg Mar 22 at 1:57
  • Thanks, that worked. More details on the formatting on the emacs wiki here and the time format in the emacs docs here. %f is the variable for the file name. – Gaurav Mar 23 at 4:31

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.