The datetime package is a LATEX2ε package that provides various different formats for \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 nodate to the package.
Since version 2.4, the datetime package has been separated into two packages: datetime and fmtcount. When I originally created this package, I defined the commands, \ordinal etc which could be used in the definition of \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 fmtcount package is now distributed separately from the datetime package, and will also need to be installed.
As from version 2.42, the datetime package is now compatible with babel, however you must load the datetime package after the babel package. For example:
There are various declarations that change the effect of \today. The change can be localised by placing the declaration within a group.
As from version 2.43, the numerical date formats (such as \ddmmyyyydate) use the command
to separate the numbers. So, for example, if you want to hyphens instead of slashes, you can do:
This declaration will redefine \today to produce the current date displayed in the form 2000/03/08. (You can redefine \dateseparator to - to change to 2000-03-08.)
This declaration will redefine \today to produce the current date displayed in the form Wednesday 8th March, 2000 if the package option dayofweek is used, or 8th March, 2000 if the package option nodayofweek is used.
This declaration will redefine \today to produce the current date displayed in the form Wed 8th Mar, 2000 if the package option dayofweek is used, or 8th Mar, 2000 if the package option nodayofweek is used.
This declaration will redefine \today to produce the current date displayed in the form 08/03/2000.
This declaration will redefine \today to produce the current date displayed in the form 8/3/2000.
This declaration will redefine \today to produce the current date displayed in the form 08/03/00.
This declaration will redefine \today to produce the current date displayed in the form 8/3/00.
This declaration will redefine \today to produce the current date displayed in the form: Wednesday the Eighth of March, Two Thousand if the package option dayofweek is used, or Eighth of March, Two Thousand if the package option nodayofweek is used. Note that \textdate is defined for use with English, it won’t look right if it is used when another language has been selected1. If you want to define a similar command for another language, you will first need to check that the fmtcount package supports that language.
This declaration will redefine \today to produce the current date displayed in the form March 8, 2000. (As TEX and LATEX do by default.)
This declaration will redefine \today to produce the current date displayed in the form 03/08/2000.
This declaration will redefine \today to produce the current date displayed in the form 3/8/2000.
This declaration will redefine \today to produce the current date displayed in the form 03/08/00.
This declaration will redefine \today to produce the current date displayed in the form 3/8/00.
In addition to the above, the declarations \date⟨lang⟩ are available for all languages defined either by calling babel prior to datetime or by passing the language name as an option to datetime. See §5 Defining New Date Formats if you want to define your own customised date format.
The current time is displayed using the command
A specific time can be displayed using the command
where ⟨hour⟩ is a number from 0 to 23, and ⟨minute⟩ and ⟨second⟩ are numbers from 0 to 59.
The format can be changed using the declaration
where ⟨style⟩ is the name of the format. Predefined formats are:
New time formats can be defined using the command:
where ⟨name⟩ is the name of the new format (used in \settimeformat), and ⟨format⟩ is how to format the time. Within ⟨format⟩ you can use the counters HOUR (number of hours after midnight), MINUTE (number of minutes past the hour), SECOND (number of seconds) HOURXII (number of hours after midnight/midday), TOHOUR (the next hour) and TOMINUTE (number of minutes to the next hour), and the corresponding commands: \THEHOUR, \THEMINUTE, \THESECOND, \THEHOURXII, \THETOHOUR and \THETOMINUTE.
For example, to define a new time format that uses a dot instead of a colon:
You then need to switch to this new format before you can use it:
As from version 2.43, if you only want to change the separator, you can simply redefine
instead of defining a new time format. For example:
The xxivtime format will now work like the dottime format defined above.
This command2 prints the date in the format required for PDF files, e.g. if the date is 1 May 2004 and time is 22:02, \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 PDFTEX. (This command is defined regardless of whether the package option nodate is called.) Example:
Note that PDFTEX introduced the new primitive \pdfcreationdate in version 1.30.0, so \pdfdate isn’t required with newer versions of PDFTEX. (\pdfcreationdate is better than \pdfdate as it also stores the time zone.)
There are two commands that print the name of the current month:
prints the current month name in full, e.g. August, and
prints the abbreviated month name, e.g. Aug. Both \monthname and \shortmonthname take an optional argument (a number from 1 to 12) if the name of a specific month is required. For example, \monthname[6] will produced the output: June.
The day of the week is computed using the algorithm documented at http://userpages.wittenburg.edu/bshelburne/Comp150/DayOfWeek.htm. This algorithm works for any date between 1st Jan, 1901 and 31st Dec, 2099. The following macros display the day of week for a given date:
prints the day of week for the specified date. For example,
will produce the output: Thursday.
prints the abbreviated name for the day of week for the specified date. For example
will produce the output: Thu.
This TEX conditional can be used to determine whether or not the option dayofweek has been passed to the package. For example:
will only display the day of week if the dayofweek option was passed to datetime. Alternatively, you can use David Carlisle’s ifthen package:
The command
displays ⟨number⟩ as a date-type ordinal. If the current language is English, this will simply pass the argument to \ordinalnum (defined in the fmtcount package), if the current language is Breton, Welsh or French, a superscript will only be added if ⟨number⟩ is 1, otherwise only ⟨number⟩ will be displayed.
The macro3
formats the specified date according to the current format of \today4. (Arguments must all be integers.) For example, in combination with \longdate, the command
will produce the output: Monday 27th September, 2004.
You can ensure that a number is displayed with at least two digits using the command
New date formats can be defined using the command:
where ⟨name⟩ is the name of the new format, and ⟨format⟩ is how to format the date. Within the argument ⟨format⟩ you can use the commands \THEDAY, \THEMONTH and \THEYEAR to represent the relevant day, month and year, or you can use the counters DAY, MONTH and YEAR if you want to use \ordinal etc. Once you have defined the new date format, you can then switch to it using the declaration \⟨name⟩ (i.e. the name you specified preceded by a backslash), and subsequent calls to \today and \formatdate will use your new format.
For example, suppose you want to define a new date format called, say, mydate, that will typeset the date in the form: 8-3-2002, then you can do:
\newdateformat will then define the declaration \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:
If the current date is, say, 8th March, 2002, the above code will produce the following: Dash: 08-03-2002. US: March 8th, 2002.
Note that \THEDAY etc and DAY etc have no real meaning outside \newdateformat (this is why they are in uppercase). Incidentally, the dashdate format is not really necessary, as you can achieve this format using:
Another note: in the above code, \ordinal was used to illustrate the use of the DAY counter. It is better to use \ordinaldate instead:
It is possible to save a date for later use using the command: 5
This date can later be displayed using the same format as that used by \formatdate using the command:
Individual elements of the date can be extracted using the commands:
The following commands are defined by the datetime package:
The following options may be passed to this package:
The default options are: long, raise, dayofweek and 24hr.
If you use the ngerman package, you must use datetime’s ngerman package option if you want the date displayed in the same form as ngerman. You must also load ngerman before you load datetime. Similarly for the german package.
If you want to use the babel package, you must load it before you load the datetime package. This is because the babel \date⟨lang⟩ commands redefine \today, whereas the datetime package redefines \today to use \formatdate, and the date formatting commands (such as \longdate) redefine \formatdate rather than \today. This ensures consistent formatting of the dates whether you use \today or \formatdate. Therefore, the datetime package has to redefine all the \date⟨lang⟩ commands accordingly. Thus the multilingual date support is mostly limited to that provided by 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 datetime override babel’s date format. For example:
will use ddmmyyyy date format regardless of language. Note that if you use a declaration instead of a package option, for example:
the date format will be switched back to \datefrench or \datespanish whenever the language is set. You can use
to always use {⟨declaration⟩} whenever the language is set. For example:
The commands \monthname and \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 \monthname⟨lang⟩. For example, \monthnamefrench[6] will produce the output: juin. Note that \textdate is formatted for English dates, and won’t look right if used with another language setting. If you want a textual date, the fmtcount package (which is loaded by datetime) defines some commands which display a number or ordinal as a word, but it only has very limited multilingual support. See the fmtcount documentation for further details.
TEX provides \day, \month and \year registers. In addition, datetime provides the registers: \currenthour, \currentminute and \currentsecond. Note that old distributions of TEX will always have \currentsecond set to zero.
As from Version 2.4, the datetime package will read in settings from the configuration file 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 datetime.cfg that contains the line:
The file datetime.cfg should then go somewhere on the TEX path. Now all you need to do is:
without having to specify the short and 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:
Whenever you use the datetime package, it will now use this format by default.
Version 2.43 and above of the datetime bundle supplies the LaTeX2HTML style file datetime.perl. This file should be placed in a directory searched by LaTeX2HTML. The following limitations apply to the LaTeX2HTML styles:
This, I agree, is an unpleasant cludge.
There is a datetime FAQ available at: http://www.dickimaw-books.com/faqs/datetimefaq.html.
A
B
babel package 7, 8, 9, 10, 11, 12, 13
C
\currenthour 14
\currentminute 15
\currentsecond 16
\currenttime 17
D
\dateseparator 18, 19, 20
datetime package 21, 22
datetime2 package 23
DAY (counter) 24, 25, 26
\day 27
\dayofweekname 28
\ddmmyydate 29
\ddmmyyyydate 30, 31
\displaydate 32
\dmyydate 33
\dmyyyydate 34
F
fmtcount package 35, 36, 37, 38, 39, 40, 41
\formatdate 42, 43, 44, 45, 46
\formattime 47
G
german package 48
\getdateday 49
\getdatemonth 50
\getdateyear 51
H
\halfpast 52
HOUR (counter) 53
HOURXII (counter) 54
I
\ifshowdow 55
ifthen package 56
L
\longdate 57, 58, 59, 60, 61
M
\mdyydate 62
\mdyyyydate 63
\midnight 64
MINUTE (counter) 65
\mmddyydate 66
\mmddyyyydate 67
MONTH (counter) 68
\month 69
\monthname 70, 71
N
\newdate 72
\newdateformat 73, 74, 75
\newtimeformat 76
ngerman package 77, 78, 79
\noon 80
O
\oclockstring 81
\ordinal 82, 83, 84
\ordinaldate 85, 86
\ordinalnum 87
P
package options:
12hr 88
24hr 89, 90
dayofweek 91, 92, 93, 94, 95, 96, 97
ddmmyy 98
ddmmyyyy 99, 100
dmyy 101
dmyyyy 102
hhmmss 103, 104
iso 105
level 106
long 107, 108
mdyy 109
mdyyyy 110
mmddyy 111
mmddyyyy 112
ngerman 113
nodate 114, 115, 116
nodayofweek 117, 118, 119, 120, 121
oclock 122
raise 123, 124
short 125, 126
text 127
us 128
yyyymmdd 129
\pdfdate 130
\pmname 131, 132
\pmstring 133, 134
Q
\quarterpast 135
\quarterto 136
S
SECOND (counter) 137
seminar package 138
\setdefaultdate 139
\settimeformat 140, 141
\shortdate 142, 143
\shortdayofweekname 144
\shortmonthname 145, 146
T
\textdate 147, 148, 149
\THEDAY 150, 151
\THEHOUR 152
\THEHOURXII 153
\THEMINUTE 154
\THEMONTH 155
\THESECOND 156
\THETOHOUR 157
\THETOMINUTE 158
\THEYEAR 159
\timeseparator 160, 161
\today 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178
TOHOUR (counter) 179
TOMINUTE (counter) 180
\twodigit 181
U
\usdate 182
1in fact, you may get an error from the fmtcount package if you are using a language that it doesn’t support.
2thanks to Ulrich Dirr for asking about this
3Note the name change since version 1.1. The command name was changed from \thedate to \formatdate to avoid a name clash when using the seminar class file.
4To be more precise, \today is defined to be \formatdate{\day}{\month}{\year} where \longdate etc change the definition of \formatdate
5Thanks to Denis Bitouzé for asking about this
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.