80

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.

3 Answers 3

108
\the\year{}

Here \year represents a number and \the lets you output it as a text.

6
  • 3
    For the sake of completeness, is there a way to get just '10
    – Geoff
    Jul 6, 2010 at 12:50
  • 7
    @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, 2011 at 19:00
  • is \year from the datetime package? Jul 27, 2012 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) Jul 27, 2012 at 17:59
  • 4
    Leaving out curly braces can cause dropped spaces. You may prefer: \the\year{}
    – jtpereyda
    Mar 9, 2014 at 4:05
13

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}
3
  • 1
    Note that this yields a 2 digit year as requested by @Geoff. Jan 31, 2012 at 3:22
  • I found that \year=10\relax would work, too.
    – Skillmon
    Aug 21, 2017 at 19:06
  • you may want to put a % after the semicolon. May 21, 2019 at 11:16
5
\documentclass{article}

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

\begin{document}
\Year 
\end{document}
4
  • 2
    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, 2011 at 19:37
  • Note that this yields a 2 digit year as requested by @Geoff. Jan 31, 2012 at 3:21
  • @egreg - did you know that Charlemagne could not write? Jan 25, 2019 at 18:13
  • 2
    @MichaelPalmer But he had scribes! :-)
    – egreg
    Jan 25, 2019 at 18:18

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.