# Is it possible to make LaTeX retrieve date information from system clock?

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
– Yiannis Lazarides Jan 15 '13 at 5:02
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}
\begin{document}
\input{date}
\end{document}

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.

-
Looks like magic.. – 4ae1e1 Jan 15 '13 at 4:55
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
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

\pdfcreationdate


which expands to a string of the form

D:20130115083308+01'00'


that is

D:YYYYMMDDHHMMSSshh'mm'


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

\def\getdate{\expandafter\getdateaux\pdfcreationdate}
\def\getdateaux#1#2#3'{\getdateaux#3'}
\def\getdateaux#1#2#3#4#5#6#7#8{%
\def\YEAR{#1#2#3#4}%
\def\MONTH{#5#6}%
\def\DAY{#7#8}}

-