7

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?

1
  • lookup datetime2. Documentation here or write texdoc datetime2 in the terminal/commandline.
    – Runar
    Commented Jun 21, 2016 at 20:49

1 Answer 1

13

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.

4
  • \DTMtoday works for me, while \today still shows the original fomrat. What could be the reason for that?
    – Max N
    Commented Mar 8, 2017 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
    Commented Mar 8, 2017 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
    Commented Mar 9, 2017 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
    Commented Mar 9, 2017 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .