2

I want \date{2015-10-10} to print 10th October, 2015 or similar. I don't want to separate the date value from the place where it is inserted into the document.

2

Along the same lines as the other answer (save it and immediately print it in a macro), but using datetime2 for formatting:

\documentclass{article}
\usepackage[en-US]{datetime2}
\newcommand{\mydate}[1]{
    \DTMsavedate{newdate}{#1}
    \DTMusedate{newdate}
}
\begin{document}
\mydate{2015-10-10}

\mydate{2015-01-01}
\end{document}

Prints:

October 10, 2015

January 1, 2015

1

The \date command does not print the date, it stores its argument on the \@date macro. Macros with @, to be used must be enclosed within \makeatletter and \makeatother. Knowing this you can make a command which takes an argument, pass it to \date and prints it afterwards:

\documentclass{article}
\makeatletter
\newcommand{\printdate}[1]{\date{#1}\@date}
\makeatother

\begin{document}
Some text \printdate{2015-12-12} \printdate{2014-12-12}
\end{document}

Note that this is an overall solution and depending on the packages you are using could not give the expected results.

  • But I believe that would print the date as given, not convert it to "December 12th, 2015". Yes? – Teepeemm Oct 21 '16 at 14:08
  • I'm not sure if that would happen always. In this case yes as there's no packages involved. – Guilherme Zanotelli Oct 21 '16 at 14:13
0

Under the british language setting for datetime2, you can set your date style using \DTMdisplaydate{YYYY}{MM}{DD}{DoW} or \DTMdate{YYYY-MM-DD}:

enter image description here

\documentclass{article}

\usepackage[british,calc]{datetime2}
\DTMlangsetup[en-GB]{ord=raise}

\DTMnewdatestyle{mydate}{%
  % #1 = year
  % #2 = month
  % #3 = day
  % #4 = day of week
  \renewcommand{\DTMdisplaydate}[4]{%
    \DTMordinal{##3} \DTMenglishmonthname{##2}, \number##1}%
}

\begin{document}

\today% ...or \DTMtoday

% \DTMdisplaydate{YYYY}{MM}{DD}{DOW}
\DTMdisplaydate{2015}{10}{10}{-1}

% \DTMdate{YYYY-MM-DD}
\DTMdate{2015-10-10}

\DTMsetdatestyle{mydate}% Set new date style
\DTMdate{2015-10-10}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.