5

Currently, when I use \date{} for an old document, I put the explicit form of the date. But this is a problem because I print all my documents in two versions, a personal version (with the form ) and a public one with the default settings.

So, I just want to give the date in a ISO format (YYYY-MM-DD) and, depending of the global settings, all dates in the document have to follow one format.

So, I ask if there is a kind of \displaydate command witch take as argument the date in ISO format and display it according to the global setting.

So there is a package like that?

  • lookup datetime2. Documentation here or write texdoc datetime2 in the terminal/commandline. – Runar Jun 21 '16 at 20:49
9

Use datetime2 where you can define your date styles and interchange them within your document (or globally) via \DTMsetdatestyle{<style>}:

enter image description here

\documentclass{article}

\usepackage[english]{datetime2}

\DTMnewdatestyle{dashdate}{%
  \renewcommand{\DTMdisplaydate}[4]{\number##1-\DTMenglishshortmonthname{##2}-\number##3}%
  \renewcommand{\DTMDisplaydate}{\DTMdisplaydate}%
}

\begin{document}

\DTMsetdatestyle{iso}
\today% ...or \DTMtoday

\DTMsetdatestyle{dashdate}
\today% ...or \DTMtoday

\DTMdisplaydate{2015}{1}{1}{-1}% Ignore Day-Of-Week

\end{document}

\DTMdisplaydate{<year>}{<month>}{<day>}{<dow>} will display a hard-coded date in the current style.

  • \DTMtoday works for me, while \today still shows the original fomrat. What could be the reason for that? – Max N Mar 8 '17 at 20:08
  • @MaxN: I see no difference between \today and \DTMtoday in my minimal example. Perhaps you are using a specialized \documentclass that adjusts/changes \today? – Werner Mar 8 '17 at 20:16
  • according to the manual ftp.fu-berlin.de/tex/CTAN/macros/latex/contrib/datetime2/… you should always specify the dow \DTMdisplaydate{2015}{1}{1}{-1} – Max N Mar 9 '17 at 19:40
  • @MaxN: It also mentions that \today might be affect if you load language-specific package like babel or polyglossia. In those instances, load order is important, and you have to load datetime2 after them. – Werner Mar 9 '17 at 19:45

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.