7

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}
3
  • 3
    Can you add a minimal working example (MWE)?
    – egreg
    Commented Oct 13, 2013 at 10:06
  • I suggest you to follow this nice tutorial here There was also an equivalent question on tex.stackexchange here, and here for the parsing, that might help you. Should you have any further problem, please do not hesitate let us know. A Mininum Working Example ([MWE](meta.tex.stackexchange.com/questions/228/…
    – Header12
    Commented Oct 13, 2013 at 10:08
  • pgf/tikz has a date library which can parse dates. It cannot parse times, though. The parsed date can be reformatted as needed. Commented Oct 13, 2013 at 11:08

1 Answer 1

12

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}
7
  • This works really well, thank you. However, it does not work together with the \svndate (which just prints the date string). The error message is: Paragraph ended before \parsecommitdate was complete.
    – Lenar Hoyt
    Commented Oct 13, 2013 at 10:37
  • 1
    @mcb You need to expand \svndate before it can be parsed. It \svndate is a one level expansion of the formatted date you can just put \expandafter before \parsecommitdate. Commented Oct 13, 2013 at 10:43
  • It doesn’t seem to work with the MWE above.
    – Lenar Hoyt
    Commented Oct 13, 2013 at 11:13
  • @mcb It compiles fine for me. In what way does it not work for you? (Does it give an error message or produce unexpected output?) Commented Oct 13, 2013 at 12:14
  • @NicolaTablot Still the same error: Paragraph ended before \parsecommitdate was complete. (I just copied my MWE from above and added package, definition from your answer and replaced the line with the date.)
    – Lenar Hoyt
    Commented Oct 13, 2013 at 12:23

You must log in to answer this question.

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