# Date format: YYYY-MM-DD

Currently I put the date in my document using: \date{\today}

How do I display the date in the YYYY-MM-DD format?

• See here ctan.org/pkg/datetime From the documentation (pg 10) we have The option yyyymmdd makes \today produce YYYY/MM/DD date – Sigur Jan 4 '14 at 13:30

edit: As noted by @Sean Allred, datetime has been superseded by datetime2.

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.

• Somebody should check whether ISO 8601 says that the separator has to be - or --. (iso.org/iso/home/standards/iso8601.htm). Definitely YYYY/MM/DD should not be used - that would violate the standard. Keith – KeithB Jan 8 '14 at 9:53
• @KeithB, Wikipedia claims, “The separator used between date values (year, month, week, and day) is the hyphen”. Also, it’s unlikely the standard mandates characters encoded neither in EBCDIC nor ASCII. – J. C. Salomon Jan 13 '14 at 19:20
• note: datetime has been superseded by datetime2 – Sean Allred Apr 6 '15 at 17:38
• Sigur is correct. However, note that the datetime package must come after the babel package. Babel seems to change the format as well. – qznc Sep 2 '15 at 12:34
• According to the CTAN page, 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.

• worked just fine in 2019. thanks! – Boris Däppen Aug 7 '19 at 12:55
• You can also use the internal \two@digits macro, which is defined as \two@digits=macro: #1->\ifnum #1<10 0\fi \number #1. – user94293 Apr 26 '20 at 9:44
• @user94293 No, I can't use such macro, because it is defined in the latex.ltx file. But I don't load such file. – wipet Apr 26 '20 at 9:56

According to the link of Sigur:

\usepackage{datetime}
\newdateformat{specialdate}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY}}
\date{\specialdate\today}


Use the package datetime2

\usepackage[style=iso]{datetime2}

• This should be an edit to the other answers using datetime since datetime is now superseded and should no longer be used for new documents. – Paul Gessler Apr 6 '15 at 17:55
• datetime2 Error: 'iso' is not a recognised dialect. – crypdick Feb 22 '17 at 18:55
• sorry but I do not see how this package is useful. It seems to force you to manually enter the date values, which it then formats.... so why not just manually write them yourself in the correct format in the document? What is this accomplishing? This answer does not actually show how to use the datetime2 to solve the problem in the question. – user5359531 Aug 31 '17 at 2:22
• The package option should be style=iso, but a numeric YYYY-MM-DD style is the default anyway, so it's not needed. – Nicola Talbot Jun 7 '18 at 11:30
• @user5359531 \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 7 '18 at 11:34

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.

• This does not answer "How do I display the date in the YYYY-MM-DD format?" and would be more useful with an actual code sample. – user5359531 Aug 31 '17 at 2:26
• It seems to change how \today works if you import it after datetime. – EL_DON Oct 8 '19 at 18:07

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}


A small contribution to wipet answer (three years later).

I change the two digit function to give two digit and only 2:

\def\twodigits[#1]{\ifnum#1<10 0\the#1\else\ifnum#1>100 \twodigits[\numexpr#1-100]\relax\else\the#1\fi\fi}


Example of use \twodigits[\year] to obtain: 18 (and not 2018)

Thanks to wipet for the contribution.

• Welcome to TeX.SX! This does not really answer the question and would probably be more appropriate as a comment. (You need 50 reputation to comment, however.) Also, I think you meant \ifnum#1>99 instead of \ifnum#1>100. – Circumscribe Jun 7 '18 at 10:39