20

I've tried googling around and all I have found is a lot of example on how to format \today. But that isn't what I want. Instead, I want a way to format historical dates based on the localization given to babel.

Say, 'June 3rd 1994' in USenglish and UKenglish?

  • 4
    Maybe datetime is an option: ctan.org/pkg/datetime – Marco Daniel Nov 1 '13 at 19:55
  • So, you want to be able to write something like \catInBox and get back August 12, 1887 (Schrodinger's birthday)? – codeAndStuff Nov 1 '13 at 20:24
  • 2
    I want to give something like {June, 3, 1994} and get back June 3rd 1994, 3rd June 1994, 6 Juin 1994,3 de junio 1994, etc. Depending on the language/localization of the document. – NictraSavios Nov 8 '13 at 9:07
14

Here's how to do it using datetime :

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[USenglish,UKenglish,french,spanish,italian]{babel}
\usepackage[nodayofweek,level]{datetime}

\newcommand{\mydate}{\formatdate{3}{6}{1994}}

\begin{document}
\selectlanguage{USenglish}
\mydate

\selectlanguage{UKenglish}
\mydate

\selectlanguage{french}
\mydate

\selectlanguage{spanish}
\mydate

\selectlanguage{italian}
\mydate

\end{document}

Result:

Image of result

Edit:

The datetime package has now been replaced with datetime2. This only requires a few minor changes to the above example:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[USenglish,UKenglish,french,spanish,italian]{babel}
\usepackage[useregional]{datetime2}

\newcommand{\mydate}{\DTMdisplaydate{1994}{6}{3}{-1}}

\begin{document}
\selectlanguage{USenglish}
\mydate

\selectlanguage{UKenglish}
\mydate

\selectlanguage{french}
\mydate

\selectlanguage{spanish}
\mydate

\selectlanguage{italian}
\mydate

\end{document}

The result looks like:

Image of result

I've used the expandable version \DTMdisplaydate. This can be used in PDF bookmarks. There's a robust non-expandable version \DTMdate that has a slightly different syntax:

\newcommand{\mydate}{\DTMdate{1994-6-3}}

The result is the same.

5

We can use the isodate package too, whith the same results as in Nicola's answere:

\documentclass[USenglish,UKenglish,french,spanish,italian]{article}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{isodate}

\begin{document}
\selectlanguage{UKenglish}
\printdate{1994-6-3}

\selectlanguage{USenglish}
\printdate{1994-6-3}

\selectlanguage{french}
\printdate{1994-6-3}

\selectlanguage{spanish}
\printdate{1994-6-3}

\selectlanguage{italian}
\printdate{1994-6-3}
\end{document}

The \printdate command allows many input formats.

enter image description here

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.