4

As datetime is superseded by datetime2, I'm struggling hard to achieve the following using the new package:

In an English document, I would like to show the current date (\today) once like this 20th December 2017 and once like this 2017-12-20.

According to the documentation, I get it right only one way globally for the whole document. I didn't find a simple example showing me how to get this done.

The answer given at https://tex.stackexchange.com/a/250057 fiddles with \@dtm@month etc. Is it that hard? It should be simple 🙄

  • 1
    Please provide a minimal working example i.e. code for a small document showing what you've got and what you've tried. – cfr Dec 20 '17 at 17:23
  • There should be absolutely no reason to fiddle with \@dtm@month in datetime2. The second method in the answer you linked to fits the design of datetime2. The first method may just as well use \month and \the\year. – Nicola Talbot Dec 20 '17 at 17:52
3

You don't need to define a new format. You can use one of the regional English day-month formats, such as en-GB, for the textual date and iso for the numeric ISO-style date:

\documentclass{article}

\usepackage[en-GB]{datetime2}

\DTMlangsetup[en-GB]{ord=level}

\begin{document}
\today. \DTMsetstyle{iso}\today.

\end{document}

Requires that both datetime2 and datetime2-english are installed.

20th December 2017. 2017-12-20.

1

In sake of coming up with a short example, I solved it myself:

\documentclass[english]{scrartcl}
\usepackage[showdow,en-GB]{datetime2}
\DTMlangsetup[en-GB]{ord=raise}

\DTMnewdatestyle{myShortDate}{%
\renewcommand{\DTMdisplaydate}[4]{\number##1-\number##2-\number##3}%
\renewcommand{\DTMDisplaydate}{\DTMdisplaydate}%
}

\DTMnewdatestyle{myLongDate}{%
\renewcommand*{\DTMenglishfmtordsuffix}{\DTMenGBfmtordsuffix}%
\renewcommand{\DTMdisplaydate}[4]{\DTMenglishordinal{##3}\ \DTMenglishmonthname{##2}\ \number##1}%
\renewcommand{\DTMDisplaydate}{\DTMdisplaydate}%
}


\begin{document}
{\DTMsetdatestyle{myShortDate}\today}\par
\today\par
{\DTMsetdatestyle{myLongDate}\today}\par
\end{document}

Though it is not as short as Nicola Talbot's answer 😕

  • This is a good example of where working on a minimal example actually helped you solve your own problem! – Werner Dec 20 '17 at 18:12
  • @Werner I know of the benefits of a minimal example. I have to admit that the datetime2 documentation is not good as a quick reference: it's hard to quickly distinguish between explanatory text, sample source code and the resulting example. – Markus Nißl Dec 20 '17 at 18:23

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.