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.

Using the LaTeX command \today, I can insert the current date. Is there any way to insert the current year with a simple command? All I want is the simple 4 digit year that shows up in \today.

share|improve this question

migrated from stackoverflow.com Jun 2 '11 at 18:12

This question came from our site for professional and enthusiast programmers.

3 Answers 3

\documentclass{article}

\def\Year{\expandafter\YEAR\the\year}
\def\YEAR#1#2#3#4{#3#4}

\begin{document}
\Year 
\end{document}
share|improve this answer
    
Of course this fails if one tries to set a letter sent by Charlemagne to the Pope or a letter sent by some future descendant that writes in year 20124. :) –  egreg Jun 2 '11 at 19:37
    
Note that this yields a 2 digit year as requested by @Geoff. –  Peter Grill Jan 31 '12 at 3:21

For the sake of Geoff's question above, here is some short code to only get the year, without changing any of the build-in macros.

\documentclass{article}
\makeatletter
\def\Year#1{%
  \def\yy@##1##2##3##4;{##3##4}%
  \expandafter\yy@#1;
}
\makeatother
\begin{document}
\Year{\the\year}
\end{document}
share|improve this answer
    
+1 Thank you for this –  Geoff Jun 2 '11 at 19:07
1  
Note that this yields a 2 digit year as requested by @Geoff. –  Peter Grill Jan 31 '12 at 3:22
\the\year

Here\yearrepresents a number and\thelets you output it as a text.

share|improve this answer
3  
For the sake of completeness, is there a way to get just '10 –  Geoff Jul 6 '10 at 12:50
5  
@Geoff: Here is a stupid one :) \newcounter{fooyear} \setcounter{fooyear}{\the\year} \addtocounter{fooyear}{-2000} and then use it in the document with '\arabic{fooyear} But its usage is limited to this century :P –  percusse Jun 2 '11 at 19:00
    
is \year from the datetime package? –  Trevor Boyd Smith Jul 27 '12 at 17:59
    
how does \the display the numerical year as a string? (i didn't know latex had datatypes... i thought everything was strings) –  Trevor Boyd Smith Jul 27 '12 at 17:59
1  
Leaving out curly braces can cause dropped spaces. You may prefer: \the\year{} –  dafrazzman Mar 9 at 4:05

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.