[Tex/LaTex] Date of file creation

datetime

When I write my notes, (I actually use lyx but that does not matter) I like to add a header with the name of file and the date the file was compiled. This I do using fancyhdr package and

\pagestyle{fancy}
\lhead{\texttt{\jobname}}
\rhead{\textsf{\today}}

(to tell the truth in lyx I have to use \jobname.lyx, but, again, this does not matter).

The point is that it would be much more useful (at least for me) to be able to print the date when the file was first created. Is there a way in TeX/LaTeX to access the time information of a latex file? I can understand the answer might be OS dependent. I am actually using a linux distribution. I looked in many other forums/FAQ but could not find the answer so far.

Best Answer

This will work on linux, with \write18 enabled; i.e., run using pdftex --shell-escape:

{\catcode`\%=12
\immediate\write18
 {/usr/bin/stat --format '\string\foo\space %yZ' \jobname.tex >\jobname.date}
 \def\foo#1 #2Z{\gdef\filedate{#1}}
 \input\jobname.date
}
The file is dated \filedate.
\bye

As I state in a comment above, you cannot get the file creation date, though. This gives you the file modification date instead.

Related Question