[Tex/LaTex] how to specify a date and then use it with a time format defined using the package datetime

datetimeformatting

I have a document in which I have some date and time formats defined using the package datetime. Specifically, I have something such as the following in the preamble:

    \newtimeformat{RFStimeA}{\twodigit{\THEHOUR}\twodigit{\THEMINUTE}\twodigit{\THESECOND}}
    \newdateformat{RFSdateA}{\THEDAY~\monthname[\THEMONTH] \THEYEAR}
    \newdateformat{RFSdateB}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY} }
    \newdateformat{RFSdateTimeA}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY}T\RFStimeA}

These defined formats can be used in the document in a manner such as the following:

This document is for the date \RFSdateB\today.

This setup works fine if the date to be typeset in the document is the current date. What I need to be able to do is switch between current dates and specified dates in a manner such as the following (in the preamble):

% Set the date.
    % Define the date.
        \date{2013-09-08}
    % Use today's date.
        %\date{\today}

What code should I use in the document (in place of something such as \RFSdateB\today) in order to be able to cope with such a 'switch' in the preamble? How should I specify the date in the preamble? Thanks for any ideas you may have!

Best Answer

You can set a new date using \newdate{<datename>}{<year>}{<month>}{<day>} and retrieve it with \displaydate{<datename>}:

enter image description here

\documentclass{article}
\usepackage{datetime}% http://ctan.org/pkg/datetime

\newtimeformat{RFStimeA}{\twodigit{\THEHOUR}\twodigit{\THEMINUTE}\twodigit{\THESECOND}}
\newdateformat{RFSdateA}{\THEDAY~\monthname[\THEMONTH] \THEYEAR}
\newdateformat{RFSdateB}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY} }
\newdateformat{RFSdateTimeA}{\THEYEAR-\twodigit{\THEMONTH}-\twodigit{\THEDAY}T\RFStimeA}

\begin{document}
RFSdateA: \RFSdateA\today \par
RFSdateB: \RFSdateB\today \par
\newdate{mydate}{8}{9}{2013}%
RFSdateA: \RFSdateA\displaydate{mydate} \par
RFSdateB: \RFSdateB\displaydate{mydate}
\end{document}