Currently I put the date in my document using: \date{\today}
How do I display the date in the YYYY-MM-DD format?
Currently I put the date in my document using: \date{\today}
How do I display the date in the YYYY-MM-DD format?
edit: As noted by @Sean Allred, datetime has been superseded by datetime2, which defaults to YYYY-MM-DD.
Using the package datetime with the option yyyymmdd as
\usepackage[yyyymmdd]{datetime}
you just change the value of \dateseparator to replace the default / by - (or -- if you want).
\renewcommand{\dateseparator}{--}
Also as noted by @Vincent, you can define your own date format.

datetime is now obsolete and has been replaced by datetime2.
– Michael Mior
Mar 19 '18 at 14:54
My solution needs no packages. The only thing you need to know is that the primitive registers \day, \month and \year include the desired information:
\def\mydate{\leavevmode\hbox{\the\year-\twodigits\month-\twodigits\day}}
\def\twodigits#1{\ifnum#1<10 0\fi\the#1}
The date in my format: \mydate.
\two@digits macro, which is defined as \two@digits=macro: #1->\ifnum #1<10 0\fi \number #1.
– user94293
Apr 26 '20 at 09:44
latex.ltx file. But I don't load such file.
– wipet
Apr 26 '20 at 09:56
\twodigits format?
– Kenneth Odle
Sep 01 '23 at 21:54
\ifcase command. You can use \ifcase\month\or January\or February\or March\or ...\or November\or December\fi.
– wipet
Oct 16 '23 at 16:02
datetime since datetime is now superseded and should no longer be used for new documents.
– Paul Gessler
Apr 06 '15 at 17:55
datetime2 to solve the problem in the question.
– user5359531
Aug 31 '17 at 02:22
style=iso, but a numeric YYYY-MM-DD style is the default anyway, so it's not needed.
– Nicola Talbot
Jun 07 '18 at 11:30
\documentclass{article}\usepackage{datetime2}\begin{document}\today\end{document} is a basic MWE that prints the current date as YYYY-MM-DD style. As for specific dates, the syntax is \DTMdate{2018-06-07} but the formatting depends on the style. So while it does just display 2018-06-07 for the default style, if you change the style it will display the date in a different format.
– Nicola Talbot
Jun 07 '18 at 11:34
According to the link of Sigur:
\usepackage{datetime}
\newdateformat{specialdate}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY}}
\date{\specialdate\today}
Use the package isodate
\usepackage[iso,german]{isodate}
It offers various options (and needs one of its language options) and commands to change the date format.
Recently (May, 2018), Donald P. Goodman III created the new package texdate.
From the package documentation:
It can print dates, advance them by numbers of days, weeks, or months, determine the weekday automatically, and print them in (mostly) arbitrary format. It can also print calendars (monthly and yearly) automatically, and can be easily localized for non-English languages.
For example, the YYYY-MM-DD format of today is:
\documentclass{article}
\usepackage{texdate}
\begin{document}
\initcurrdate
\printfdate{ISOext}
\end{document}
I found an easier way to get today's date in YYYY-MM-DD format:
\newcommand\twodigits[1]{%
\ifnum#1<10 0#1\else #1\fi
}
\number\year-\twodigits{\number\month}-\twodigits{\number\day}
Dear Mary,
Today I have received what I need to tell you;
I was taking a walk and I finally know what advice to give.
In the words of the great Kanye West,
\textit{"If you have the opportunity to play this game called life,
you have to appreciate every moment."}
Keep striving toward success, and that is what you will become.
Also linux $>$ windows.
Best, \
John Doe
Result:
\twodigits by just conditioning for the prefix: \newcommand{\twodigits}[1]{\ifnum#1<10 0\fi#1}. Also, your output doesn't include the -s.
– Werner
Mar 01 '22 at 19:23
yyyymmddmakes\todayproduceYYYY/MM/DDdate – Sigur Jan 04 '14 at 13:30