Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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...

share|improve this question
    
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? –  KevinSayHi 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 2 days ago

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
Looks like magic.. –  KevinSayHi 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? –  KevinSayHi 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

\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}}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.