3

I'd like to typeset dates with the datetime2 package in English in the format commonly used in scientific or technical writing, that is:

  • time in 24-hour format;
  • dates in the format: "29 October 2018" (no commas, no ordinals).

How can this be done? None of the English language packages seem to support this format. I'm using LuaLaTeX and polyglossia, just in case it matters. Thank you.

5

You can use \DTMsettimestyle to set a time style that overrides the current date-time style. The English datetime2 styles that use day month year ordering all have options ord, daymonthsep and monthyearsep that allow you to make minor adjustments to the way the ordinal is display and the separators between the day and month and between the month and year.

For example, with en-GB the default options are ord=level, daymonthsep={\space} and monthyearsep={\space}, so the only option that needs changing for your required date style is ord:

\documentclass{article}

\usepackage[en-GB]{datetime2}

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

\DTMsettimestyle{iso}

\begin{document}
Today: \today. Current time: \DTMcurrenttime.

\end{document}

(Other locales may have different default options. Check the datetime2-english documentation for available locales and their settings.)

The date style uses the en-GB regional style, because en-GB is used as a package option, but the time style uses iso because \DTMsettimestyle overrides the date-time style (set implicitly with \DTMsetstyle{en-GB} when the package was loaded). This produces:

Today: 29 October 2018. Current time: 17:53:53.

If you don't want the seconds with the iso style you can use the showseconds=false package option:

\usepackage[en-GB,showseconds=false]{datetime2}

With polyglossia, you need to move \DTMsettimestyle after the language change otherwise it will be reset:

\documentclass{article}

\usepackage{polyglossia}
\setmainlanguage[variant=uk]{english}
\usepackage[en-GB,showseconds=false]{datetime2}

\DTMlangsetup[en-GB]{ord=omit,daymonthsep={\space}}

\begin{document}
\DTMsettimestyle{iso}

Today: \today. Current time: \DTMcurrenttime.

\end{document}

Other options include modifying the appropriate language date hook. For example:

\documentclass{article}

\usepackage{polyglossia}
\setmainlanguage[variant=uk]{english}
\usepackage[en-GB,showseconds=false]{datetime2}

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

\renewcommand{\dateenglish}{%
  \DTMsetdatestyle{en-GB}%
  \DTMsettimestyle{iso}%
}

\begin{document}

Today: \today. Current time: \DTMcurrenttime.

\end{document}

Alternatively, if the document only has a single language, use useregional=false and set both the date and time style as appropriate in the preamble. For example:

\documentclass{article}

\usepackage{polyglossia}
\setmainlanguage[variant=uk]{english}
\usepackage[en-GB,useregional=false,showseconds=false]{datetime2}

\DTMlangsetup[en-GB]{ord=omit,daymonthsep={\space}}
\DTMsetdatestyle{en-GB}
\DTMsettimestyle{iso}

\begin{document}

Today: \today. Current time: \DTMcurrenttime.

\end{document}

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.