Well, this question is pretty weird ;) I know TeX is strictly sandboxed, but I guess there is at least some possibility? After all, system clock (for instance, UNIX time on UNIX-like systems) is only 8 bytes or so in memory.

I would be very impressed if retrieving date information in LaTeX is actually possible! :D That way I would be able to create such a template that I do not need to adjust the date of each new article...

  • BTW If you need only date, there are counters like \year and \month. – Eddy_Em Jan 15 '13 at 4:39
  • @Eddy_Em Then how do you convert \month to "January", "February", etc.? A bunch of if statements? – 4ae1e1 Jan 15 '13 at 4:57
  • This is quite simple and realised in language packages: \def\monthname{\ifcase\month\or January\or February… \fi} – Eddy_Em Jan 15 '13 at 5:17
  • Where do you get the idea that TeX is 'strictly sandboxed'?! – cfr Jul 26 '14 at 23:52

You mean something like that

cat wr.tex
\immediate\write18{date > date.tex}

latex -enable-write18 wr.tex


If you don't need time but need only date, there are counters like \year, \month and \day.

To put current year in text say \number\year, to put month number use same construction. To put month name there must be a construction in your babel file like \today (puts today's date to document) or you can make construction like

\def\monthname{\ifcase\month\or January\or February\or March … \fi}

Then macro \monthname will write current month' name to the document.

| improve this answer | |
  • Looks like magic.. – 4ae1e1 Jan 15 '13 at 4:55
  • 1
    No magic: \write18 executes a shell command, \immediate do in right now (without it command can run in the end of compilation what can do an error in \input). By default (what if someone put \write18{rm -rf ~}?) \write18 disabled, to enable it you must tell -enable-write18 to latex. – Eddy_Em Jan 15 '13 at 5:20
  • Thanks for help. I accepted this but actually I prefer the counters you mentioned in comment. Could you please edit this answer to also include that method? – 4ae1e1 Jan 15 '13 at 5:40
  • Done. I've added some info. – Eddy_Em Jan 15 '13 at 5:48
  • 1
    One should note that on Unix systems the option is -shell-escape, which is recognized also by the last versions of MiKTeX. – egreg Jan 15 '13 at 7:28

However, the integer registers \year, \month and \day contain date information you probably need. Also \time contains the number of minutes from midnight when the job started.

For more detailed information, with pdftex (so with latex and pdflatex that use the same binary program), you can access the creation date that will be stamped in the PDF file with


which expands to a string of the form


that is


where s is + or - and together with hh and mm gives the local offset from UTC. The command is available also with luatex but not with XeTeX.

So, for instance, if you want to get the year, month and day, you can say

| improve this answer | |

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.