# Date without year

I would like the dates language within a document controlled by package. It seems that datetime2 is the only contemporary package doing this stuff. However, occasionally I need only to display day and month without year, i.e.

21th March


Is that possible? I know that there is undocumented (!) showdayofmonth flag (Month/Year Format in Latex) that does that for the day, but I couldn't find similar for the year.

Maybe I should try another package? Maybe babel? What would you suggest?

MWE

\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional]{datetime2}

\begin{document}

\DTMDisplaydate{0}{2}{10}{-1}

\end{document}

• Could you make a small MWE to make it faster to try answers? – Marijn Sep 20 '20 at 13:20
• Defining a new command derived from datetime2. – Bernard Sep 20 '20 at 13:24
• @Bernard but this command will not work for different languages? – Pygmalion Sep 20 '20 at 13:27
• I don't know, as I haven't looked into the code of the package, but I think it should be possible to patch one of the commands to obtain what you want. – Bernard Sep 20 '20 at 13:39
• Actually when reading the source code of datetime2 I found that there is an undocumented showyear key: \DTMlangsetup*{showyear=false}. Related question (but not duplicate): tex.stackexchange.com/questions/358256/…. – Marijn Sep 21 '20 at 8:57

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:

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.

• The problem with this solution is that it is not language independent. Is it possible to remove year from all language date displays? – Pygmalion Sep 21 '20 at 7:47

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}