LaTeX – How to Parse and Convert Date Strings

datetime

I’m using svn-multi to include the date of the most recent Subversion commit of my documents. However, the string has the format 2013-10-13 11:05:51 +0200 (Sun, 13 Oct 2013). Is it possible to convert this string to the same date format that is used by \today?

Here is a minimal working example (Subversion inserts the date automatically before a commit):

\documentclass{article}

\usepackage{svn-multi}
\svnidlong
{$LastChangedBy: mcb $}
{$LastChangedRevision: 23 $}
{$LastChangedDate: 2013-10-13 11:05:51 +0200 (Sun, 13 Oct 2013) $}
{$HeadURL: http://example.org $}

\title{Sample Document}
\author{Sample}
\date{\svndate}

\begin{document}

\maketitle

\end{document}

Best Answer

Here's how to parse the date. The other answer gives links on adjusting the display:

\documentclass{article}

\usepackage{datetime}

\def\parsecommitdate#1-#2-#3 #4:#5:#6 #7\endparse{%
  \date{\formatdate{#3}{#2}{#1}}%
}

\newcommand{\svndate}{2013-10-13 11:05:51 +0200 (Sun, 13 Oct 2013)}

\title{Sample Document}
\author{Sample}

\begin{document}

% Since \svndate is not available in the preamble the date must be set in the document environment.
\expandafter\parsecommitdate\svndate\endparse

\maketitle


\end{document}