[Tex/LaTex] How to make a new date format with abbreviated names of months with the datetime package

datetime

I am looking to save and re-use dates which needs to be displayed in a format such as Oct. 25.

How do I do that please?

I read the documentation in datetime package. They do have shortmonthname which would display months by the abbreviation. They also allows storing and displaying stored dates. But I don't know how to combine the two.

Best Answer

With datetime dates can be stored to a symbolic name, say 'mydate' with \newsavedate{mydate}{daynumber}{monthnumber}{yearnumber}

\displaydate{mydate} will display this date using the current date format, whereas \getdatemonth{mydate} will extract the month of the saved date.

Using \shortmonthname[\getdatemonth{mydate}] it's possible to show the 3-letter abbreviation of the month (see the example)

\documentclass{article}

\usepackage{datetime}

\usepackage{xcolor}
\newdate{mydate}{23}{10}{2015}

\begin{document}
Not today: \displaydate{mydate}

The month of \displaydate{mydate} is \textcolor{red}{\shortmonthname[\getdatemonth{mydate}]}

\end{document}

enter image description here

Update

Using a \newdateformat any call to \mydateformat will show this format, that's why a 'wrapper macro' (or grouping) is appropiate:

\documentclass{article}

\usepackage{datetime}

\newdateformat{mydateformat}{\shortmonthname[\THEMONTH]. \THEDAY}
\newcommand{\myshortformat}[1]{%
{% group here!
  \mydateformat%
  \displaydate{#1}%
}%
}


\usepackage{xcolor}
\newdate{mydate}{23}{10}{2015}

\begin{document}
Not today: \displaydate{mydate}

The month of \displaydate{mydate} is \textcolor{red}{\shortmonthname[\getdatemonth{mydate}]}

The saved date was in (short format): \myshortformat{mydate}

Today is: \today

\end{document}

enter image description here

Related Question