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.

Welcome to tex.sx! Note that you don't have to (and shouldn't) sign with your name since it automatically appears in the lower right corner of your post
–
SeamusFeb 28 '11 at 12:35

8

On linux, there is no such thing as the date the file was first created. There are three timestamps on a file, known as mtime, atime and ctime. Here mtime is the time of last modification, atime is the time of last access, and ctime has a more technical definition that is irrelevant here.
–
Harald Hanche-OlsenFeb 28 '11 at 12:41

Oops! You are right Harald, I na"ively thought ctime was creation time. Your observation preatty much nullifys my question. But I did find all the answer useful, I am sorry I can not vote them up.
–
lcvFeb 28 '11 at 14:37

Googling tells me that there is a "birthtime" and the stat command line utility under linux can display that time. Can't verify that, for I don't have a linux box right here.
–
topskipFeb 28 '11 at 19:32

@Patrick: Google is hardly an authority here. Both man pages for stat (ch 1 for the command, ch 2 for the system call) confirm that there are only the three time stamps I mentioned above.
–
Harald Hanche-OlsenMar 1 '11 at 11:57

Martin's answer surely makes more sense than this one. But I leave my answer here in case someone could use the technique for something related.
–
Harald Hanche-OlsenFeb 28 '11 at 15:03

Yes this is the sort of answer I was thinking of. Thanks to Martin as well.
–
lcvFeb 28 '11 at 16:59

1

@Icv: My solution turned out to only return the file modification date, not the creation date as I thought at the beginning. So Harald's answer is the correct one. Note that you can write a % using \@percentchar which saves you the trouble of changing the catcode.
–
Martin Scharrer♦Mar 1 '11 at 11:26

@Martin: No, my solution too gives modification date. Linux doesn't keep track of any creation date, so there is no way to get it.
–
Harald Hanche-OlsenMar 1 '11 at 11:59

Yes true, but under Windows such an approach should work and return the creation time. The difficulty might be to find a stat program under Windows.
–
Martin Scharrer♦Mar 1 '11 at 12:40

Update: In the meantime I published the filemod package which can display and compare file modification dates. With this the modification date of the main file can be printed using \filemodprint{\jobname}.

pdftex provides the expandable primitive \pdffilemoddate which takes the file name in question as argument:

\pdffilemoddate{filename.tex}

or

\pdffilemoddate{\jobname.tex}

This works with all files, not just PDFs like the name might suggest.
It expands to the file modification date. The format is like D:20110228133815Z, which then can be parsed using a macro. Note that all characters of this string have the catcode other not letter.

The following code defines a macro which reads every number of the returned string an finally passes it to a format macro which can be freely redefined.
For help with formatting the date see this question or other questions tagged with datetime.

how can I use this stuff to just get the date, without any extra boxes, newlines, etc? I tried \getfiledate[notime,datecolor=black,putprefix=false]{animalEstimation.tex} but it creates some nasty new lines (this is inside the \date{} tag)
–
GrzenioMar 8 '13 at 15:48