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?

Solutions Collecting From Web of "Date format: YYYY-MM-DD"

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.

enter image description here

According to the link of Sigur:

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

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.

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}