2

I would like to combine the advdate package for relative dates and the datetime2 package for custom formatting. However, the datetime2 package seems to undo whatever advdate does. I've only found examples on here that use the datetime package, but I'd prefer not to rely on this (now obsolete) package. Is there a way to accomplish this?

MWE: (Note that the dates are as intended when I comment out the second line.)

\usepackage{advdate} 
\usepackage{datetime2}

\begin{document} Today is \today. \SetDate[01/01/2022] But January 1st, 2022 is not \today. \end{document}````

mimuller
  • 800

1 Answers1

3

The two packages use very different ways of operating. When you do \SetDate, the internal registers \day, \month and \year are set to what's requested.

On the other hand, datetime2 redefines \today to use its own methods; specifically, it does

\newcommand*{\DTMtoday}{%
 \DTMdisplaydate
  {\@dtm@currentyear}%
  {\@dtm@currentmonth}%
  {\@dtm@currentday}%
  {\@dtm@currentdow}%
}
\let\today\DTMtoday

You can interface the two packages by adding some code to \FixDate:

\documentclass{article}
\usepackage{advdate}
\usepackage{datetime2}
\usepackage{etoolbox}

\makeatletter \appto\FixDate{% \edef@dtm@currentyear{\the\year}% \edef@dtm@currentmonth{\the\month}% \edef@dtm@currentday{\the\day}% } \makeatother

\begin{document}

Today is \today.

\SetDate[01/01/2022]

And January 1st, 2022 is \today.

\end{document}

enter image description here

egreg
  • 1,121,712