[Tex/LaTex] Insert arbitrary date

datetimeformatting

I want to simply insert an arbitrary date (in my case March 16, 2015) in a way that does not hard code the date format.

That is, I want something like

\insertdate{<year}{<month>}{day}

For example:

\insertdate{2015}{03}{16}

which with the English configuration can insert

March 16, 2015

… but with for example Norwegian settings (given that month names and style are available) can insert

16. mars, 2015

I do not need (or want) a reference to the date after it is inserted, only that the format is not hard coded. I've found this related question, but find it hard to believe that what I want cannot be done out of the box.

  1. Is there a package that lets me insert a general date and formats the date based on locale settings?
  2. Is there an easy way to change the locale settings for this package?

Best Answer

The datetime package can give you the desired result using \date<language> and \formatdate. A little example:

\documentclass{article}
\usepackage[italian,spanish,french,swedish,ngerman]{babel}
\usepackage[ddmmyyyy]{datetime}

\begin{document}

Auf Deutsch:

\datengerman{\today}

\datengerman\formatdate{16}{03}{2004}

\selectlanguage{swedish}
P\r{a} svenska:

\dateswedish\today

\dateswedish\formatdate{16}{03}{2004}

\selectlanguage{french}
En Fran\c{c}ais:

\datefrench\today

\datefrench\formatdate{16}{03}{2004}

\selectlanguage{spanish}
En espa\~nol:

\datespanish\today

\datespanish\formatdate{16}{03}{2004}

\selectlanguage{italian}
In Italiano:

\dateitalian\today

\dateitalian\formatdate{16}{03}{2004}

\end{document}

enter image description here