# 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 at 17:38

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.

-

Use the package datetime2

\usepackage[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 at 17:55

My solution needs no packages. Only, what you need to know, is that the primitive registers \day, \monthand\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.
`
-