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.
Asked
Active
Viewed 4.0k times
88
Display Name
- 46,933
Amandasaurus
- 2,501
- 3
- 14
- 9
3 Answers
14
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}
yannisl
- 117,160
5
\documentclass{article}
\def\Year{\expandafter\YEAR\the\year}
\def\YEAR#1#2#3#4{#3#4}
\begin{document}
\Year
\end{document}
-
2Of 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 02 '11 at 19:37
-
-
-
2
'10– Geoff Jul 06 '10 at 12:50\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 02 '11 at 19:00\yearfrom thedatetimepackage? – Trevor Boyd Smith Jul 27 '12 at 17:59\thedisplay 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\the\year{}– jtpereyda Mar 09 '14 at 04:05\the\monthjust prints6for June instead of06– somenxavier Jun 25 '21 at 19:15