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


(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
    – Seamus
    Feb 28, 2011 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. Feb 28, 2011 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.
    – lcv
    Feb 28, 2011 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.
    – topskip
    Feb 28, 2011 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. Mar 1, 2011 at 11:57

5 Answers 5


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

 {/usr/bin/stat --format '\string\foo\space %yZ' \jobname.tex >\jobname.date}
 \def\foo#1 #2Z{\gdef\filedate{#1}}
The file is dated \filedate.

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

  • 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. Feb 28, 2011 at 15:03
  • Yes this is the sort of answer I was thinking of. Thanks to Martin as well.
    – lcv
    Feb 28, 2011 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. Mar 1, 2011 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. Mar 1, 2011 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. Mar 1, 2011 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:




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 .


   #1-#2-#3\ #4:#5:#6%

  • I did not know about this. However, when I look for it in the pdftex documentation, I think you meant \pdffilemoddate, not \pdfcreationdate. Feb 28, 2011 at 14:29
  • @Harald: Yes, you are right. I was under the impression that both are taken a file name as argument, which isn't the case. Thanks! Feb 28, 2011 at 14:52

For every document you write, the creation date is not going to change, by definition.

This means that it is perfectly acceptable to hard code the date in. For example,

\rhead{\textsf{28\textsuperscript{th} Febuary, 2011}}

or formatted however you want. This would keep the date the creation date, because it doesn't need to dynamically change every time you compile the document.

If I have misunderstood what you want to do, let me know.


There is 'getfiledate' package on CTAN and TeXLive.


  • 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)
    – Grzenio
    Mar 8, 2013 at 15:48

If you are after the modification date, then the package filemod seems to do exactly what you need. To get the last modified date of the file you just include the package in the usual way:


and the modification time of the current document is printed by:


you can also print the modification time, and there are many options to format the output.

  • See the bottom of Martin Scharrer's answer; he's the package author :-). Mar 8, 2013 at 16:33
  • @HendrikVogt: Now at the top of my answer. Thanks for notifying me. Mar 8, 2013 at 18:12

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.