# Display an index of dates

I write a document which tells a story long of a few months, and I would like to display an index of the main dates at the end. For example, I would like to type something like (french format): On January the first \indexdate{01/01/2018}..., so the final index would look like this.

- 2018
January, 1st : 2
January, 3rd : 4, 6
January, 21th : 12-13, 15


Is there a package which would allow me to do something like this? Or, is it possible to do a such index without having to manually compute a timestamp or something for the ordering of each date? Thanks!

• Welcome to TeX.SE! Often it helps to do a google search like site:tex.stackexchange.com index date in this case, which has lead me to this post. I am not saying that this is necessarily the answer to your question, but would suggest that you go through the results of such searches in order to get a feeling of what has already been done. – user121799 Oct 6 '18 at 19:01

A proof of concept that should be easily adaptable to your purpose and language.

\documentclass{article}
\usepackage{imakeidx}
\usepackage{etoolbox}
\usepackage[english]{datetime2}
\usepackage[level]{fmtcount}

\makeindex

\newcommand{\indexdate}[1]{% date in format MM-DD
\index{#1@\computedate{#1}}%
}
\makeatletter
\newrobustcmd{\computedate}[1]{\compute@date#1\@nil}
\def\compute@date#1-#2\@nil{%
\DTMenglishmonthname{#1}\space\ordinalnum{#2}%
}
\makeatother

\begin{document}

This happened on January 1st\indexdate{01-01}.

This happened on July 4th\indexdate{07-04}.

This happened on December 25th\indexdate{12-25}.

\clearpage

This happened on October 31st\indexdate{10-31}.

This happened on January 1st\indexdate{01-01}.

This happend on January 13th\indexdate{01-13}.

\printindex

\end{document}


There's actually no need that \indexdate follows a date, here it's done just for ease of verification of the output.

It's important to express the date in numeric format (with two digits) for correct sorting.

If the header is modified into

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}

\usepackage{imakeidx}
\usepackage{etoolbox}
\usepackage[french]{datetime2}
\usepackage[level]{fmtcount}

\makeindex

\newcommand{\indexdate}[1]{% date in format MM-DD
\index{#1@\computedate{#1}}%
}
\makeatletter
\newrobustcmd{\computedate}[1]{\compute@date#1\@nil}
\def\compute@date#1-#2\@nil{%
\DTMfrenchordinal{#2} \DTMfrenchmonthname{#1}%
}
\makeatother


the same document body as before would produce

• Thanks! I slightly modified your code to have different entries for different years and months, so I have the following: \makeindex[name=dateindex, title=Index des dates] \newcommand{\indexdate}[3]{\index[dateindex]{#3!\DTMfrenchmonthname{#2}!#3#2#1@\DTMdate{#3-#2-#1}}}. – Michael Marx Oct 7 '18 at 19:36