Date without year
Edit: there is an undocumented showyear
key. You can apply this for a single language using for example \DTMsetbool{en-GB}{showyear}{false}
or for all languages using \DTMlangsetup{showyear=false}
. The second version issues a warning because the key is not applicable to some regions in the hierarchy, such as english-base
. This warning can be suppressed using \DTMlangsetup*
(see datetime2 -- Warnings when using showyear setting).
This setting changes the behavior of \DTMDisplaydate
throughout the document, but you can reset it after use.
MWE:
\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional]{datetime2}
\begin{document}
\DTMlangsetup*{showyear=false}
\DTMDisplaydate{2020}{2}{10}{-1} is the date
\DTMlangsetup*{showyear=true}
\DTMDisplaydate{2020}{2}{10}{-1} is the date
\end{document}
Result:
Original answer:
You can define a new date format without year, as described in the manual (e.g., page 96 and further).
When you want to use the new format you need to set it using \DTMsetdatestyle
which will affect \DTMDisplaydate
. It does not seem possible to set it just for single use, so afterwards you need to reset the style to what it was before, in the MWE this is en-GB
(because of main=british
). Note that you need to add the calc
package option for datetime2
to use the \DTMmonthname
macro.
MWE:
\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional,calc]{datetime2}
\begin{document}
\DTMnewdatestyle{noyear}{%
\renewcommand{\DTMdisplaydate}[4]{%
\DTMenglishordinal{##3} \DTMmonthname{##2}}%
}
\DTMsetdatestyle{noyear}
\DTMDisplaydate{2020}{2}{10}{-1}
\DTMsetdatestyle{en-GB}
\DTMDisplaydate{2020}{2}{10}{-1}
\end{document}
Result:
Note that the redefinition includes \DTMenglishordinal
in order to keep the ordinal (th) from being printed as superscript. A more international version is \ordinalnum
from the fmtcount
package (which supports a number of European languages) but only as superscript as far as I know.
I introduce \stripyear
to help.
\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional]{datetime2}
\newcommand\stripyear[1]{%
\edef\tmp{#1}\expandafter\stripyearaux\tmp\relax}
\def\stripyearaux#1 #2 #3\relax{#1 #2}
\begin{document}
\stripyear{\DTMDisplaydate{2020}{2}{10}{-1}}.
\end{document}