9

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 🙄

0

2 Answers 2

4

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.

3

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 😕

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .