# Formatted date inside section

I am trying to compile a document where each section title corresponds to a given date. The date has to be formatted, 2014/01/03 should produce 3rd January 2014 in the title.

I was trying to use the isodate package like this:

\documentclass[english]{report}

\usepackage{verbatim}
\usepackage{isodate}
\usepackage{hyperref}

\begin{document}

\tableofcontents
\newpage

%Date formatting routines
\dateinputformat{tex}
\origdate

\section{\printdate{2014/01/03}}
% Some normal lines of text
\verbatiminput{../20140103.txt}
\pagebreak

\section{\printdate{2014/01/04}}
% Some normal lines of text
\verbatiminput{../20140104.txt}
\pagebreak

\end{document}


but this is reporting errors.

Some details:

• The document will have more than 50 different sections (each with a different date).
• I don't mind using other date formatting packages or options
• I have a script that produces the section blocks from the filename automatically.
• I've tried to escape the \printdate with a protect but has not worked.

I have read this question. However, I need a lot of different sections each with a different date. I guess there has to be a straightforward way to do this.

• Welcome to TeX.SX! What is the error reported? – user31729 Jul 8 '15 at 15:08
• It should be \printdate{2014-01-03}; if you use / as separator, the input should be dd/mm/yyyy. – egreg Jul 8 '15 at 15:13
• @ChristianHupfer The error is: ! Undefined control sequence. \su@IfSubStringInString ...}\su@compare #2#1\@nil l.86 \subsection{\printdate{2014-01-04}} – mcieec Jul 8 '15 at 15:15
• @egreg I've also tested with the dd/mm/yyyy format. Still the same error. – mcieec Jul 8 '15 at 15:17
• I get no error; the version of isodate is isodate 2010/01/03 v2.30; I tried with TeX Live 2008, 2009, 2010, 2011, 2012, 2013, 2014 and 2015, without any error. – egreg Jul 8 '15 at 15:38

The 'problem' is hyperref -- it tries to create bookmarks automatically, writing pdf string content to the bookmarks. Apparently \printdate does not provide such pdf string content. The usage of bookmarks can be prevented with bookmarks=false option to hyperref.

A working solution, however, not with 'correct' date formatting in the bookmarks, is to use \texorpdfstring{\printdate{...}}{...}, where the 2nd argument content goes to the bookmark and the first one is for the section title/ToC.

\documentclass[english]{report}

\usepackage{verbatim}
\usepackage{isodate}

\usepackage{hyperref}
\usepackage{bookmark}

\newcommand{\printdatetitle}[1]{%
\texorpdfstring{\printdate{#1}}{#1}%
}

\makeatletter
%\providecommand{\@nil}
\makeatother

\dateinputformat{tex}

\begin{document}
\tableofcontents
\chapter{First}
\section{\printdatetitle{2014/1/3}}

\end{document}

• Thanks @ChristianHupfer! This is enough for my requirements. – mcieec Jul 8 '15 at 16:52
• @mcieec: Alright, but I'll try to find a better way, to get the non-pdf-conforming output of printdate working – user31729 Jul 8 '15 at 16:54

Since you said you don't mind using another package, here's a solution that uses datetime2 instead. This package is a replacement to datetime and was designed to provide expandable commands so that the date can be used in bookmarks. Example:

\documentclass[english]{report}

\usepackage[en-GB]{datetime2}
\usepackage{hyperref}

\def\iprintdate#1/#2/#3/{\DTMdisplaydate{#1}{#2}{#3}{-1}}
\newcommand*{\printdate}[1]{\iprintdate#1/}

\begin{document}

\tableofcontents
\newpage

\section{\printdate{2014/01/03}}
Some normal lines of text
\pagebreak

\section{\printdate{2014/01/04}}
Some normal lines of text
\pagebreak

\end{document}


The dates appear as "3rd January 2014" and "4th January 2014" in the bookmarks (as well as in the table of contents and the section headings).

If you don't already have them installed, in addition to datetime2, you also need to install datetime2-english (for the en-GB option) and tracklang.