datetime2 package FAQ

How do I make the date appear in my regional format instead of the default ISO format? 🔗

First, you need to make sure that you have the relevant datetime2 language module installed. For example, to display the date in the en-GB style (British English) you need to install the datetime2-english module using your TeX package manager. (This needs to be done in addition to installing datetime2.)

Next you need to ensure that datetime2 picks up the correct locale setting for your document. Unfortunately, this doesn’t always work (see Localisation with tracklang.tex).

You can explicitly set the locale in the datetime2 package option list. For example:

\usepackage[en-GB]{datetime2}
If the language has been loaded before datetime2 then you need to explicitly switch on regional support. For example:
\documentclass[british]{article}
\usepackage{babel}
\usepackage[useregional]{datetime2}
If you prefer a numeric regional style then you need useregional=numeric.

Each style comes with its own set of options that are relevant to the particular style. These should be set using \DTMlangsetup. For example:

\documentclass{article}
\usepackage[en-GB,en-US]{datetime2}

\DTMlangsetup[en-GB]{ord=raise,abbr,monthyearsep={,\space}}
\DTMlangsetup[en-US]{dayyearsep={,\space}}

\begin{document}
GB date: \DTMsetstyle{en-GB}\DTMdate{2021-06-31}.

US date: \DTMsetstyle{en-US}\DTMdate{2021-06-31}.
\end{document}
This produces:
GB date: 31st Jun, 2021.

US date: June 31, 2021.

2021-05-08 22:01:45


Permalink: https://www.dickimaw-books.com/faq.php?id=254
Alternative link: https://www.dickimaw-books.com/faq.php?itemlabel=datetime2useregional

Category: datetime2 package
Topic: Localisation