1

I want to use strings for dates in my document that can be formatted either as ISO or German later on.

I looked at isodate datetime and datetime2 most promising seemed to be the latest, but the months don't show up in German.

However in a document

\usepackage{datetime2}
\DTMsetstyle{german}
\today
\DTMDisplaydate{2017}{3}{8}{-1} 

\today is expanded correctly as 8. März 2017, but \DTMDisplaydate{2017}{3}{8}{-1} results in 8. 3 2017 which is not correct, it should either be heute 8. 3. 2017 or 8. März 2017

3

Based on the expected output, just use \DTMdisplaydate rather than \DTMDisplaydate:

9. März 2017
8. März 2017

\documentclass{article}

\usepackage[ngerman]{babel}% ...or load \usepackage[ngerman]{datetime2} below

\usepackage{datetime2}
\DTMsetstyle{german}

\begin{document}

\today

\DTMdisplaydate{2017}{3}{8}{-1}

\end{document}
3

For datetime2-german, \DTMDisplaydate should be the same as \DTMdisplaydate, but I made an error (mostly probably from copy and pasting from another language file that has lower case months). The simplest method is to use Werner's solution (just use \DTMdisplaydate). If you need \DTMDisplaydate (for example, you may be switching languages), then either wait for version 1.1 2017-03-09 (which I've just uploaded) or redefine the style:

\documentclass{article}

\usepackage[ngerman]{babel}
\usepackage[useregional]{datetime2}

\DTMrenewdatestyle
{german}%
{% 
  \renewcommand*\DTMdisplaydate[4]{%
    \DTMifbool{german}{showdayofmonth}%
    {\DTMgermanordinal{##3}\DTMgermandaymonthsep}%
    {}%
    \DTMgermanmonthname{##2}%
    \DTMifbool{german}{showyear}%
    {%
      \DTMgermanmonthyearsep
      \number##1 % space intended
    }%
    {}%
  }%
  \renewcommand{\DTMDisplaydate}{\DTMdisplaydate}%
}

\begin{document}

\today.
\DTMDisplaydate{2017}{3}{8}{-1} 

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.