Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.

datetime2 package FAQ

How do I change my document from datetime.sty? 🔗

The default date format in datetime2.sty has changed to ISO so if your old document looked like:

\documentclass{article}
\usepackage{datetime}
\begin{document}
\today
\end{document}
then the date would be formatted in British English style: Saturday 28th March, 2015. If you simply replace datetime with datetime2:
\documentclass{article}
\usepackage{datetime2}
\begin{document}
\today
\end{document}
then the date would be formatted in ISO style: 2015-03-28. If you want to reproduce the British format you need to make sure you have also installed datetime2-english and load it using package options:
\documentclass{article}
\usepackage[en-GB,showdow]{datetime2}
\begin{document}
\today
\end{document}
This now displays the date in the style Saturday 28th March 2015, which is slightly different from the datetime.sty format. You can also use british instead of en-GB, but take care if you try loading it as a document class option. If you try
\documentclass[british]{article}
\usepackage[showdow]{datetime2}
\begin{document}
\today
\end{document}
this once again produces the ISO format 2015-03-28 but you can now switch to the British style using \DTMsetstyle{en-GB} or do
\documentclass[british]{article}
\usepackage[useregional,showdow]{datetime2}
\begin{document}
\today
\end{document}
Similarly if you use babel:
\documentclass[british]{article}
\usepackage{babel}
\usepackage[useregional,showdow]{datetime2}
\begin{document}
\today
\end{document}
If you want the suffix as a superscript you need to add
\DTMlangsetup[en-GB]{ord=raise}
before you display the date. If you additionally want the comma you need to do:
\DTMlangsetup[en-GB]{ord=raise,monthyearsep={,\space}}
datetime2.sty uses different command names to datetime.sty (except for \today) and prefixes them all to prevent clashes with other packages. It also uses an ISO year month day way of specifying dates in command arguments to avoid confusion. For example
\formatdate{28}{3}{2014}% datetime.sty
needs to be replaced with
\DTMdisplaydate{2014}{3}{28}{-1}% datetime2.sty
or
\DTMdate{2014-3-28}% datetime2.sty
Note that \DTMdate isn’t expandable (but can calculate the week day, if enabled) whereas \DTMdisplaydate is expandable (but can’t calculate the week day).

Saving dates has similarly changed from:

\newdate{mydate}{28}{3}{2015}% datetime.sty
to
\DTMsavedate{mydate}{2015-03-28}% datetime2.sty
Using the dates has changed from:
\displaydate{mydate}% datetime.sty
to
\DTMusedate{mydate}% datetime2.sty

2023-04-14 10:16:36


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

Category: datetime2 package
Topic: General