\documentclass{nlctdoc} \usepackage[colorlinks, bookmarks, bookmarksopen, hyperindex=false, pdfauthor={Nicola L.C. Talbot}, pdftitle={datetime.sty: A Date and Time Package}, pdfkeywords={date,time,LaTeX}]{hyperref} \usepackage{creatdtx} \begin{document} \RecordChanges \OnlyDescription \title{datetime.sty v2.60: Formatting Current Date and Time} \author{Nicola L. C. Talbot\\[10pt] Dickimaw Books\\ \url{http://www.dickimaw-books.com/}} \date{2015-03-20} \maketitle \begin{important} This is the last version of this package. The replacement package is called \sty{datetime2} and will be released shortly after the this final version. \end{important} \tableofcontents \section{Introduction} \changes{1.0}{2000/08/08}{First release} \changes{1.01}{2000/09/18}{Documentation added} The \styfmt{datetime} package is a \LaTeXe\ package that provides various different formats for \ics{today}, and provides commands for displaying the current time. If you only want the time commands but not the date changing commands, you can pass the option \pkgopt{nodate} to the package. \changes{2.3}{2004/05/01}{nodate package option added} \changes{2.41}{2004/10/22}{split package into two files: datetime.sty and fmtcount.sty} Since version 2.4, the \styfmt{datetime} package has been separated into two packages: \styfmt{datetime} and \sty{fmtcount}. When I originally created this package, I defined the commands, \ics{ordinal} etc which could be used in the definition of \cs{today}. Since then, I have extended the number of commands available that can be used to display the value of a \LaTeX\ counter, however it seems more appropriate to define all these counter-related commands in a separate package. The \sty{fmtcount} package is now distributed separately from the \styfmt{datetime} package, and will also need to be installed. \changes{2.42}{2004/11/01}{made package compatible with babel} As from version 2.42, the \styfmt{datetime} package is now compatible with \sty{babel}, however you must load the \styfmt{datetime} package \emph{after} the \sty{babel} package. For example: \begin{verbatim} \usepackage[francais]{babel} \usepackage{datetime} \end{verbatim} \section{Predefined Date Formats} There are various declarations that change the effect of \ics{today}. The change can be localised by placing the declaration within a group. As from version 2.43, the numerical date formats (such as \ics{ddmmyyyydate}) use the command \begin{definition}[\DescribeMacro{\dateseparator}] \cs{dateseparator} \end{definition} to separate the numbers. So, for example, if you want to hyphens instead of slashes, you can do: \begin{verbatim} \renewcommand{\dateseparator}{-} \end{verbatim} \subsection{ISO format} \begin{definition}[\DescribeMacro{\yyyymmdddate}] \cs{yyyymmdddate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 2000/03/08. (You can redefine \ics{dateseparator} to \texttt{-} to change to 2000-03-08.) \subsection{\texorpdfstring{\meta{Day} \meta{Month} \meta{Year}}{Day Month Year} formats} \begin{definition}[\DescribeMacro{\longdate}] \cs{longdate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form Wednesday 8\textsuperscript{th} March, 2000 if the package option \pkgopt{dayofweek} is used, or 8\textsuperscript{th} March, 2000 if the package option \pkgopt{nodayofweek} is used. \begin{definition}[\DescribeMacro{\shortdate}] \cs{shortdate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form Wed 8\textsuperscript{th} Mar, 2000 if the package option \pkgopt{dayofweek} is used, or 8\textsuperscript{th} Mar, 2000 if the package option \pkgopt{nodayofweek} is used. \begin{definition}[\DescribeMacro{\ddmmyyyydate}] \cs{ddmmyyyydate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 08/03/2000. \begin{definition}[\DescribeMacro{\dmyyyydate}] \cs{dmyyyydate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 8/3/2000. \begin{definition}[\DescribeMacro{\ddmmyydate}] \cs{ddmmyydate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 08/03/00. \begin{definition}[\DescribeMacro{\dmyydate}] \cs{dmyydate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 8/3/00. \begin{definition}[\DescribeMacro{\textdate}] \cs{textdate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form: Wednesday the Eighth of March, Two Thousand if the package option \pkgopt{dayofweek} is used, or Eighth of March, Two Thousand if the package option \pkgopt{nodayofweek} is used. Note that \cs{textdate} is defined for use with English, it won't look right if it is used when another language has been selected\footnote{in fact, you may get an error from the \sty{fmtcount} package if you are using a language that it doesn't support.}. If you want to define a similar command for another language, you will first need to check that the \sty{fmtcount} package supports that language. \subsection{\texorpdfstring{\meta{Month} \meta{Day} \meta{Year}}{Month Day Year} formats} \begin{definition}[\DescribeMacro{\usdate}] \cs{usdate} \end{definition} This declaration will redefine \cs{today} to produce the current date displayed in the form March 8, 2000. (As \TeX\ and \LaTeX\ do by default.) \begin{definition}[\DescribeMacro{\mmddyyyydate}] \cs{mmddyyyydate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 03/08/2000. \begin{definition}[\DescribeMacro{\mdyyyydate}] \cs{mdyyyydate} \end{definition} This declaration will redefine \verb"\today" to produce the current date displayed in the form 3/8/2000. \begin{definition}[\DescribeMacro{\mmddyydate}] \cs{mmddyydate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 03/08/00. \begin{definition}[\DescribeMacro{\mdyydate}] \cs{mdyydate} \end{definition} This declaration will redefine \ics{today} to produce the current date displayed in the form 3/8/00. \subsection{Dates defined by \texorpdfstring{\styfmt{babel}}{babel}} In addition to the above, the declarations \cs{date}\meta{lang} are available for all languages defined either by calling \sty{babel} prior to \styfmt{datetime} or by passing the language name as an option to \styfmt{datetime}. See~\sectionref{sec:newdate} if you want to define your own customised date format. \section{Time Commands} The current time is displayed using the command \begin{definition}[\DescribeMacro{\currenttime}] \cs{currenttime} \end{definition} A specific time can be displayed using the command \begin{definition}[\DescribeMacro{\formattime}] \cs{formattime}\marg{hour}\marg{minute}\marg{second} \end{definition} where \meta{hour} is a number from~0 to~23, and \meta{minute} and \meta{second} are numbers from~0 to~59. The format can be changed using the declaration \begin{definition}[\DescribeMacro{\settimeformat}] \cs{settimeformat}\marg{style} \end{definition} where \meta{style} is the name of the format. Predefined formats are: \begin{description} \item[xxivtime] Twenty-four hour time in the form 22:28 (Default) \item[hhmmsstime] Twenty-four hour time in the form 22:28:00 \item[ampmtime] Twelve hour time in the form 10:28pm \item[oclock] Displays the current time as a string, e.g.\ Twenty-Eight minutes past Ten in the afternoon. \end{description} New time formats can be defined using the command: \begin{definition}[\DescribeMacro{\newtimeformat}] \cs{newtimeformat}\marg{name}\marg{format} \end{definition} where \meta{name} is the name of the new format (used in \ics{settimeformat}), and \meta{format} is how to format the time. Within \meta{format} you can use the counters \ctr{HOUR} (number of hours after midnight), \ctr{MINUTE} (number of minutes past the hour), \ctr{SECOND} (number of seconds) \ctr{HOURXII} (number of hours after midnight/midday), \ctr{TOHOUR} (the next hour) and \ctr{TOMINUTE} (number of minutes to the next hour), and the corresponding commands: \ics{THEHOUR}, \ics{THEMINUTE}, \ics{THESECOND}, \ics{THEHOURXII}, \ics{THETOHOUR} and \ics{THETOMINUTE}. For example, to define a new time format that uses a dot instead of a colon: \begin{verbatim} \newtimeformat{dottime}{\twodigit{\THEHOUR}.\twodigit{\THEMINUTE}} \end{verbatim} You then need to switch to this new format before you can use it: \begin{verbatim} \settimeformat{dottime} \currenttime \end{verbatim} As from version 2.43, if you only want to change the separator, you can simply redefine \begin{definition}[\DescribeMacro{\timeseparator}] \cs{timeseparator} \end{definition} instead of defining a new time format. For example: \begin{verbatim} \renewcommand{\timeseparator}{.} \end{verbatim} The \texttt{xxivtime} format will now work like the \texttt{dottime} format defined above. \section{Formating Dates} \begin{definition}[\DescribeMacro{\pdfdate}] \cs{pdfdate} \end{definition} This command\footnote{thanks to Ulrich Dirr for asking about this} prints the date in the format required for PDF files, e.g.\ if the date is 1 May 2004 and time is 22:02, \verb"\pdfdate" will print 20040501220200. The reason this date format is separate from all the others is because the other form doesn't get properly expanded by PDF\TeX. (This command is defined regardless of whether the package option \texttt{nodate} is called.) Example: \begin{verbatim} \pdfinfo{ /Author (Me) /Title (A Sample Document) /CreationDate (D:20040501215500) /ModDate (D:\pdfdate) } \end{verbatim} \textbf{Note} that PDF\TeX\ introduced the new primitive \cs{pdfcreationdate} in version 1.30.0, so \cs{pdfdate} isn't required with newer versions of PDF\TeX. (\cs{pdfcreationdate} is better than \cs{pdfdate} as it also stores the time zone.) There are two commands that print the name of the current month: \begin{definition}[\DescribeMacro{\monthname}] \cs{monthname}\oarg{num} \end{definition} prints the current month name in full, e.g.\ August, and \begin{definition}[\DescribeMacro{\shortmonthname}] \cs{shortmonthname}\oarg{num} \end{definition} prints the abbreviated month name, e.g.\ Aug. Both \cs{monthname} and \cs{shortmonthname} take an optional argument (a number from 1 to 12) if the name of a specific month is required. For example, \verb"\monthname[6]" will produced the output: June. The day of the week is computed using the algorithm documented at \url{http://userpages.wittenburg.edu/bshelburne/Comp150/DayOfWeek.htm}. This algorithm works for any date between 1\textsuperscript{st} Jan, 1901 and 31\textsuperscript{st} Dec, 2099. The following macros display the day of week for a given date: \begin{definition}[\DescribeMacro{\dayofweekname}] \cs{dayofweekname}\marg{day}\marg{month}\marg{year} \end{definition} prints the day of week for the specified date. For example, \begin{verbatim} \dayofweekname{31}{10}{2002} \end{verbatim} will produce the output: Thursday. \begin{definition}[\DescribeMacro{\shortdayofweekname}] \cs{shortdayofweekname}\meta{day}\marg{month}\marg{year} \end{definition} prints the abbreviated name for the day of week for the specified date. For example \begin{verbatim} \shortdayofweekname{31}{10}{2002} \end{verbatim} will produce the output: Thu. \begin{definition}[\DescribeMacro{\ifshowdow}] \cs{ifshowdow} \end{definition} This \TeX\ conditional can be used to determine whether or not the option \pkgopt{dayofweek} has been passed to the package. For example: \begin{verbatim} \ifshowdow\dayofweekname{31}{10}{2002} \fi \end{verbatim} will only display the day of week if the \pkgopt{dayofweek} option was passed to \styfmt{datetime}. Alternatively, you can use David~Carlisle's \sty{ifthen} package: \begin{verbatim} \ifthenelse{\boolean{showdow}}{\dayofweekname{31}{10}{2002} }{} \end{verbatim} The command \begin{definition}[\DescribeMacro{\ordinaldate}] \cs{ordinaldate}\marg{number} \end{definition} displays \meta{number} as a date-type ordinal. If the current language is English, this will simply pass the argument to \ics{ordinalnum} (defined in the \sty{fmtcount} package), if the current language is Breton, Welsh or French, a superscript will only be added if \meta{number} is 1, otherwise only \meta{number} will be displayed. The macro\footnote{Note the name change since version 1.1. The command name was changed from \cs{thedate} to \cs{formatdate} to avoid a name clash when using the \sty{seminar} class file.} \begin{definition}[\DescribeMacro{\formatdate}] \cs{formatdate}\marg{day}\marg{month}\marg{year} \end{definition} formats the specified date according to the current format of \ics{today}\footnote{To be more precise, \ics{today} is defined to be \ics{formatdate}\{\cs{day}\}\{\cs{month}\}\{\cs{year}\} where \ics{longdate} etc change the definition of \cs{formatdate}}. (Arguments must all be integers.) For example, in combination with \ics{longdate}, the command \begin{verbatim} \formatdate{27}{9}{2004} \end{verbatim} will produce the output: Monday 27\textsuperscript{th} September, 2004. You can ensure that a number is displayed with at least two digits using the command \begin{definition}[\DescribeMacro{\twodigit}] \cs{twodigit}\marg{num} \end{definition} \section{Defining New Date Formats}\label{sec:newdate} New date formats can be defined using the command: \begin{definition}[\DescribeMacro{\newdateformat}] \cs{newdateformat}\marg{name}\marg{format} \end{definition} where \meta{name} is the name of the new format, and \meta{format} is how to format the date. Within the argument \meta{format} you can use the commands \ics{THEDAY}, \ics{THEMONTH} and \ics{THEYEAR} to represent the relevant day, month and year, or you can use the counters \ctr{DAY}, \ctr{MONTH} and \ctr{YEAR} if you want to use \ics{ordinal} etc. Once you have defined the new date format, you can then switch to it using the declaration \verb'\'\meta{name} (i.e.\ the name you specified preceded by a backslash), and subsequent calls to \ics{today} and \ics{formatdate} will use your new format. For example, suppose you want to define a new date format called, say, \texttt{mydate}, that will typeset the date in the form: 8-3-2002, then you can do: \begin{verbatim} \newdateformat{mydate}{\THEDAY-\THEMONTH-\THEYEAR} \end{verbatim} \ics{newdateformat} will then define the declaration \cs{mydate} which can be used to switch to your new format. In the following example, two new date formats are defined, and they are then selected to produce two different formats for the current date: \begin{verbatim} \newdateformat{dashdate}{% \twodigit{\THEDAY}-\twodigit{\THEMONTH}-\THEYEAR} \newdateformat{usvardate}{% \monthname[\THEMONTH] \ordinal{DAY}, \THEYEAR} Dash: \dashdate\today. US: \usvardate\today. \end{verbatim} If the current date is, say, 8th March, 2002, the above code will produce the following: Dash: 08-03-2002. US: March 8\textsuperscript{th}, 2002. Note that \ics{THEDAY} etc and \ctr{DAY} etc have no real meaning outside \ics{newdateformat} (this is why they are in uppercase). Incidentally, the \texttt{dashdate} format is not really necessary, as you can achieve this format using: \begin{verbatim} \renewcommand{\dateseparator}{-} \ddmmyyyydate \end{verbatim} Another note: in the above code, \ics{ordinal} was used to illustrate the use of the \ctr{DAY} counter. It is better to use \ics{ordinaldate} instead: \begin{verbatim} \newdateformat{usvardate}{% \monthname[\THEMONTH] \ordinaldate{\THEDAY}, \THEYEAR} \end{verbatim} \section{Saving Dates} It is possible to save a date for later use using the command: \footnote{Thanks to Denis Bitouz\'e for asking about this} \begin{definition}[\DescribeMacro{\newdate}] \cs{newdate}\marg{name}\marg{day}\marg{month}\marg{year} \end{definition} This date can later be displayed using the same format as that used by \ics{formatdate} using the command: \begin{definition}[\DescribeMacro{\displaydate}] \cs{displaydate}\marg{name} \end{definition} Individual elements of the date can be extracted using the commands: \begin{definition}[\DescribeMacro{\getdateday}] \cs{getdateday}\marg{name} \end{definition} \begin{definition}[\DescribeMacro{\getdatemonth}] \cs{getdatemonth}\marg{name} \end{definition} \begin{definition}[\DescribeMacro{\getdateyear}] \cs{getdateyear}\marg{name} \end{definition} \section{Predefined Names} The following commands are defined by the \styfmt{datetime} package: \begin{tabular}{ll} \bfseries Command Name & \bfseries Default Value\\ \ics{dateseparator} & \verb'/'\\ \ics{timeseparator} & \verb':'\\ \ics{amname} & \texttt{am}\\ \ics{pmname} & \texttt{pm}\\ \ics{amorpmname} & \ics{amname} if morning, otherwise \ics{pmname}\\ \ics{amstring} & \texttt{in the morning}\\ \ics{pmstring} & \texttt{in the afternoon}\\ \ics{amorpmstring} & \ics{amstring} if morning, otherwise \ics{pmstring}\\ \ics{halfpast} & \texttt{Half past}\\ \ics{quarterpast} & \texttt{Quarter past}\\ \ics{quarterto} & \texttt{Quarter to}\\ \ics{noon} & \texttt{Noon}\\ \ics{midnight} & \texttt{Midnight}\\ \ics{oclockstring} & \texttt{O'Clock} \end{tabular} \section{Package Options} The following options may be passed to this package: \begin{description} \item[\pkgopt{long}] make \cs{today} produce long date \item[\pkgopt{short}] make \cs{today} produce short date \item[\pkgopt{yyyymmdd}] make \cs{today} produce YYYY/MM/DD date \item[\pkgopt{ddmmyyyy}] make \cs{today} produce DD/MM/YYYY date \item[\pkgopt{dmyyyy}] make \cs{today} produce D/M/YYYY date \item[\pkgopt{ddmmyy}] make \cs{today} produce DD/MM/YY date \item[\pkgopt{dmyy}] make \cs{today} produce D/M/YY date \item[\pkgopt{text}] make \cs{today} produce text date in UK style \item[\pkgopt{us}] make \cs{today} produce US style date \item[\pkgopt{mmddyyyy}] make \cs{today} produce MM/DD/YYYY date \item[\pkgopt{mdyyyy}] make \cs{today} produce M/D/YYYY date \item[\pkgopt{mmddyy}] make \cs{today} produce MM/DD/YY date \item[\pkgopt{mdyy}] make \cs{today} produce M/D/YY date \item[\pkgopt{raise}] make ordinal st,nd,rd,th appear as superscript \item[\pkgopt{level}] make ordinal st,nd,rd,th appear level with rest of text \item[\pkgopt{dayofweek}] make the day of week appear for \ics{longdate}, \ics{shortdate} or \ics{textdate} \item[\pkgopt{nodayofweek}] don't display the day of week. \item[\pkgopt{hhmmss}] make \cs{currenttime} produce \texttt{hhmmsstime} format \item[\pkgopt{24hr}] make \cs{currenttime} produce \texttt{xxivtime} format \item[\pkgopt{12hr}] make \cs{currenttime} produce \texttt{ampmtime} format \item[\pkgopt{oclock}] make \cs{currenttime} produce \texttt{oclock} format \item[\pkgopt{nodate}] Don't redefine \cs{today} or define the month or day of week commands (useful if you only want the time commands) \item[\pkgopt{iso}] as \pkgopt{ddmmyyyy} and \pkgopt{hhmmss} but also sets date separator to \texttt{-} and time separator to \texttt{:} \end{description} The default options are: \pkgopt{long}, \pkgopt{raise}, \pkgopt{dayofweek} and \pkgopt{24hr}. \section{Multilingual Support} If you use the \sty{ngerman} package, you must use \styfmt{datetime}'s \pkgopt{ngerman} package option if you want the date displayed in the same form as \sty{ngerman}. You must also load \sty{ngerman} \emph{before} you load \styfmt{datetime}. Similarly for the \sty{german} package. If you want to use the \sty{babel} package, you must load it \emph{before} you load the \styfmt{datetime} package. This is because the \sty{babel} \cs{date}\meta{lang} commands redefine \ics{today}, whereas the \sty{datetime} package redefines \cs{today} to use \ics{formatdate}, and the date formatting commands (such as \ics{longdate}) redefine \cs{formatdate} rather than \cs{today}. This ensures consistent formatting of the dates whether you use \cs{today} or \cs{formatdate}. Therefore, the \styfmt{datetime} package has to redefine all the \cs{date}\meta{lang} commands accordingly. Thus the multilingual date support is mostly limited to that provided by \sty{babel}. Additional support, such as the day of week names and abbreviations, are only supplied for those languages that I know, or that other people have been able to supply for me. As from v2.56, the package options supplied to \styfmt{datetime} override \sty{babel}'s date format. For example: \begin{verbatim} \usepackage[french,spanish]{babel} \usepackage[ddmmyyyy]{datetime} \end{verbatim} will use ddmmyyyy date format regardless of language. Note that if you use a declaration instead of a package option, for example: \begin{verbatim} \usepackage[french,spanish]{babel} \usepackage{datetime} \ddmmyyyydate \end{verbatim} the date format will be switched back to \cs{datefrench} or \cs{datespanish} whenever the language is set. You can use \begin{definition}[\DescribeMacro{\setdefaultdate}] \cs{setdefaultdate}\marg{declaration} \end{definition} to always use \marg{declaration} whenever the language is set. For example: \begin{verbatim} \setdefaultdate{\ddmmyyyydate} \end{verbatim} The commands \ics{monthname} and \ics{shortmonthname}, will produce the month name in the current language. If you want the month name in a specific language, you can use the command \cs{monthname}\meta{lang}. For example, \verb"\monthnamefrench[6]" will produce the output: juin. Note that \ics{textdate} is formatted for English dates, and won't look right if used with another language setting. If you want a textual date, the \sty{fmtcount} package (which is loaded by \styfmt{datetime}) defines some commands which display a number or ordinal as a word, but it only has very limited multilingual support. See the \sty{fmtcount} documentation for further details. \section{Registers} \TeX\ provides \ics{day}, \ics{month} and \ics{year} registers. In addition, \styfmt{datetime} provides the registers: \ics{currenthour}, \ics{currentminute} and \ics{currentsecond}. Note that old distributions of \TeX\ will always have \cs{currentsecond} set to zero. \section{Configuration File} As from Version 2.4, the \styfmt{datetime} package will read in settings from the configuration file \texttt{datetime.cfg}, if it exists, which will override the default package options. For example, suppose you prefer a short date without the day of week by default, you will need to create a file called \texttt{datetime.cfg} that contains the line: \begin{verbatim} \shortdate\showdowfalse \end{verbatim} The file \texttt{datetime.cfg} should then go somewhere on the \TeX\ path. Now all you need to do is: \begin{verbatim} \usepackage{datetime} \end{verbatim} without having to specify the \pkgopt{short} and \pkgopt{nodayofweek} options. You can also use this file to define and set your own date styles. For example, you could create a configuration file that has the following lines: \begin{verbatim} \newdateformat{dashdate}{\twodigit{\THEDAY}-\twodigit{\THEMONTH}-\THEYEAR} \dashdate \end{verbatim} Whenever you use the \styfmt{datetime} package, it will now use this format by default. \section{LaTeX2HTML styles} \changes{2.43}{2005/02/25}{Added LaTeX2HTML support}% \changes{2.44}{2005/03/03}{Fixed minor bugs in Perl scripts} Version 2.43 and above of the \styfmt{datetime} bundle supplies the LaTeX2HTML style file \texttt{datetime.perl}. This file should be placed in a directory searched by LaTeX2HTML. The following limitations apply to the LaTeX2HTML styles: \begin{itemize} \item The configuration file \texttt{datetime.cfg} is currently ignored. You can however do: \begin{verbatim} \usepackage{datetime} \html{\input{datetime.cfg}} \end{verbatim} This, I agree, is an unpleasant cludge. \item The commands \cs{monthname}\meta{language} are not implemented. \item Some of the languages are not implemented. \item The package option \pkgopt{nodate} is not implemented. \end{itemize} \section{Troubleshooting} There is a \sty{datetime} FAQ available at: \url{http://www.dickimaw-books.com/faqs/datetimefaq.html}. \StopEventually{\phantomsection \addcontentsline{toc}{section}{Index}\PrintIndex } \end{document}