datetime.sty v2.59: Formatting Current Date and Time

Nicola L. C. Talbot
Dickimaw Books



1 Introduction
2 Predened Date Formats
 2.1 ISO format
 2.2 hDayihMonthihYeari formats
 2.3 hMonthihDayihYeari formats
 2.4 Dates dened by babel
3 Time Commands
4 Formating Dates
5 Dening New Date Formats
6 Saving Dates
7 Predened Names
8 Package Options
9 Multilingual Support
10 Registers
11 Conguration File
12 LaTeX2HTML styles
13 Troubleshooting

1 Introduction

The datetime package is a LATEX2" package that provides various dierent 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 dened the commands, \ordinal etc which could be used in the denition 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 dene 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:



2 Predened Date Formats

There are various declarations that change the eect 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

\dateseparator  \dateseparator

to separate the numbers. So, for example, if you want to hyphens instead of slashes, you can do:



2.1 ISO format

\yyyymmdddate  \yyyymmdddate

This declaration will redene \today to produce the current date displayed in the form 2000/03/08. (You can redene \dateseparator to - to change to 2000-03-08.)


2.2 hDayihMonthihYeari formats

\longdate  \longdate

This declaration will redene \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.

\shortdate  \shortdate

This declaration will redene \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.

\ddmmyyyydate  \ddmmyyyydate

This declaration will redene \today to produce the current date displayed in the form 08/03/2000.

\dmyyyydate  \dmyyyydate

This declaration will redene \today to produce the current date displayed in the form 8/3/2000.

\ddmmyydate  \ddmmyydate

This declaration will redene \today to produce the current date displayed in the form 08/03/00.

\dmyydate  \dmyydate

This declaration will redene \today to produce the current date displayed in the form 8/3/00.

\textdate  \textdate

This declaration will redene \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 dened for use with English, it won't look right if it is used when another language has been selected1. If you want to dene a similar command for another language, you will rst need to check that the fmtcount package supports that language.


2.3 hMonthihDayihYeari formats

\usdate  \usdate

This declaration will redene \today to produce the current date displayed in the form March 8, 2000. (As TEX and LATEX do by default.)

\mmddyyyydate  \mmddyyyydate

This declaration will redene \today to produce the current date displayed in the form 03/08/2000.

\mdyyyydate  \mdyyyydate

This declaration will redene \today to produce the current date displayed in the form 3/8/2000.

\mmddyydate  \mmddyydate

This declaration will redene \today to produce the current date displayed in the form 03/08/00.

\mdyydate  \mdyydate

This declaration will redene \today to produce the current date displayed in the form 3/8/00.


2.4 Dates dened by babel

In addition to the above, the declarations \datehlangi are available for all languages dened either by calling babel prior to datetime or by passing the language name as an option to datetime. See 5 Dening New Date Formats if you want to dene your own customised date format.


3 Time Commands

The current time is displayed using the command

\currenttime  \currenttime

A specic time can be displayed using the command

\formattime  \formattime{hhouri}{hminutei}{hsecondi}

where hhouri is a number from 0 to 23, and hminutei and hsecondi are numbers from 0 to 59.

The format can be changed using the declaration

\settimeformat  \settimeformat{hstylei}

where hstylei is the name of the format. Predened formats are:

Twenty-four hour time in the form 22:28 (Default)
Twenty-four hour time in the form 22:28:00
Twelve hour time in the form 10:28pm
Displays the current time as a string, e.g. Twenty-Eight minutes past Ten in the afternoon.

New time formats can be dened using the command:

\newtimeformat  \newtimeformat{hnamei}{hformati}

where hnamei is the name of the new format (used in \settimeformat), and hformati is how to format the time. Within hformati 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 dene 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 redene

\timeseparator  \timeseparator

instead of dening a new time format. For example:


The xxivtime format will now work like the dottime format dened above.


4 Formating Dates

\pdfdate  \pdfdate

This command2 prints the date in the format required for PDF les, 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 dened regardless of whether the package option nodate is called.) Example:

   /Author (Me)  
   /Title (A Sample Document)  
   /CreationDate (D:20040501215500)  
   /ModDate (D:\pdfdate)  

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:

\monthname  \monthname[hnumi]

prints the current month name in full, e.g. August, and

\shortmonthname  \shortmonthname[hnumi]

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 specic month is required. For example, \monthname[6] will produced the output: June.

The day of the week is computed using the algorithm documented at 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:

\dayofweekname  \dayofweekname{hdayi}{hmonthi}{hyeari}

prints the day of week for the specied date. For example,


will produce the output: Thursday.

\shortdayofweekname  \shortdayofweeknamehdayi{hmonthi}{hyeari}

prints the abbreviated name for the day of week for the specied date. For example


will produce the output: Thu.

\ifshowdow  \ifshowdow

This TEX conditional can be used to determine whether or not the option dayofweek has been passed to the package. For example:

\ifshowdow\dayofweekname{31}{10}{2002} \fi

will only display the day of week if the dayofweek option was passed to datetime. Alternatively, you can use David Carlisle's ifthen package:

\ifthenelse{\boolean{showdow}}{\dayofweekname{31}{10}{2002} }{}

The command

\ordinaldate  \ordinaldate{hnumberi}

displays hnumberi as a date-type ordinal. If the current language is English, this will simply pass the argument to \ordinalnum (dened in the fmtcount package), if the current language is Breton, Welsh or French, a superscript will only be added if hnumberi is 1, otherwise only hnumberi will be displayed.

The macro3

\formatdate  \formatdate{hdayi}{hmonthi}{hyeari}

formats the specied 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

\twodigit  \twodigit{hnumi}


5 Dening New Date Formats

New date formats can be dened using the command:

\newdateformat  \newdateformat{hnamei}{hformati}

where hnamei is the name of the new format, and hformati is how to format the date. Within the argument hformati 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 dened the new date format, you can then switch to it using the declaration \hnamei (i.e. the name you specied preceded by a backslash), and subsequent calls to \today and \formatdate will use your new format.

For example, suppose you want to dene 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 dene the declaration \mydate which can be used to switch to your new format. In the following example, two new date formats are dened, and they are then selected to produce two dierent formats for the current date:

\monthname[\THEMONTH] \ordinal{DAY}, \THEYEAR}  
Dash: \dashdate\today.  
US: \usvardate\today.

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:

\monthname[\THEMONTH] \ordinaldate{\THEDAY}, \THEYEAR}


6 Saving Dates

It is possible to save a date for later use using the command: 5

\newdate  \newdate{hnamei}{hdayi}{hmonthi}{hyeari}

This date can later be displayed using the same format as that used by \formatdate using the command:

\displaydate  \displaydate{hnamei}

Individual elements of the date can be extracted using the commands:

\getdateday  \getdateday{hnamei}

\getdatemonth  \getdatemonth{hnamei}

\getdateyear  \getdateyear{hnamei}


7 Predened Names

The following commands are dened by the datetime package:

Command NameDefault Value
\dateseparator /
\amname am
\pmname pm
\amorpmname \amname if morning, otherwise \pmname
\amstring in the morning
\pmstring in the afternoon
\amorpmstring \amstring if morning, otherwise \pmstring
\halfpast Half past
\quarterpast Quarter past
\quarterto Quarter to
\noon Noon
\midnight Midnight
\oclockstring O’Clock


8 Package Options

The following options may be passed to this package:

make \today produce long date
make \today produce short date
make \today produce YYYY/MM/DD date
make \today produce DD/MM/YYYY date
make \today produce D/M/YYYY date
make \today produce DD/MM/YY date
make \today produce D/M/YY date
make \today produce text date in UK style
make \today produce US style date
make \today produce MM/DD/YYYY date
make \today produce M/D/YYYY date
make \today produce MM/DD/YY date
make \today produce M/D/YY date
make ordinal st,nd,rd,th appear as superscript
make ordinal st,nd,rd,th appear level with rest of text
make the day of week appear for \longdate, \shortdate or \textdate
don't display the day of week.
make \currenttime produce hhmmsstime format
make \currenttime produce xxivtime format
make \currenttime produce ampmtime format
make \currenttime produce oclock format
Don't redene \today or dene the month or day of week commands (useful if you only want the time commands)
as ddmmyyyy and hhmmss but also sets date separator to - and time separator to :

The default options are: long, raise, dayofweek and 24hr.


9 Multilingual Support

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 \datehlangi commands redene \today, whereas the datetime package redenes \today to use \formatdate, and the date formatting commands (such as \longdate) redene \formatdate rather than \today. This ensures consistent formatting of the dates whether you use \today or \formatdate. Therefore, the datetime package has to redene all the \datehlangi 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

\setdefaultdate  \setdefaultdate{hdeclarationi}

to always use {hdeclarationi} 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 specic language, you can use the command \monthnamehlangi. 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) denes 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.

There is currently only limited multilingual support for \dayofweekname and \shortdayofweekname (just English, French, Portuguese, Spanish and German6). You can add support for other languages by dening the commands \dayofweeknameidhlangi and \shortdayofweeknameidhlangi. Note that these commands only take one argument which should be a number from 1 to 7 indicating the day of the week.

You can use the following as templates. Replace english with the name of your language (as given by \languagename) and replace Sunday etc as appropriate:

\or Sunday%  
\or Monday%  
\or Tuesday%  
\or Wednesday%  
\or Thursday%  
\or Friday%  
\or Saturday%  
\or Sun%  
\or Mon%  
\or Tue%  
\or Wed%  
\or Thu%  
\or Fri%  
\or Sat%  

If you want them added to future versions of datetime, please post them on my feature request form at: Please use LATEX commands to produce accents to ensure encoding independence. (For example, use \’e instead of .)


10 Registers

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.


11 Conguration File

As from Version 2.4, the datetime package will read in settings from the conguration le 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 le called datetime.cfg that contains the line:


The le 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 le to dene and set your own date styles. For example, you could create a conguration le that has the following lines:


Whenever you use the datetime package, it will now use this format by default.


12 LaTeX2HTML styles

Version 2.43 and above of the datetime bundle supplies the LaTeX2HTML style le datetime.perl. This le should be placed in a directory searched by LaTeX2HTML. The following limitations apply to the LaTeX2HTML styles:


13 Troubleshooting

There is a datetime FAQ available at:




\amname  1, 2
\amorpmname  3
\amorpmstring  4
\amstring  5, 6

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, 23
\day  24
DAY counter  25, 26, 27
\dayofweekname  28, 29
\ddmmyydate  30
\ddmmyyyydate  31, 32
\displaydate  33
\dmyydate  34
\dmyyyydate  35

F fmtcount package  36, 37, 38, 39, 40, 41, 42
\formatdate  43, 44, 45, 46, 47
\formattime  48

G german package  49
\getdateday  50
\getdatemonth  51
\getdateyear  52

H \halfpast  53
HOUR counter  54
HOURXII counter  55

I \ifshowdow  56
ifthen package  57

L \languagename  58
\longdate  59, 60, 61, 62, 63

M \mdyydate  64
\mdyyyydate  65
\midnight  66
MINUTE counter  67
\mmddyydate  68
\mmddyyyydate  69
\month  70
MONTH counter  71
\monthname  72, 73

N \newdate  74
\newdateformat  75, 76, 77
\newtimeformat  78
ngerman package  79, 80, 81
\noon  82

O \oclockstring  83
\ordinal  84, 85, 86
\ordinaldate  87, 88
\ordinalnum  89

P package options:
    12hr  90
    24hr  91, 92
    dayofweek  93, 94, 95, 96, 97, 98, 99
    ddmmyy  100
    ddmmyyyy  101, 102
    dmyy  103
    dmyyyy  104
    hhmmss  105, 106
    iso  107
    level  108
    long  109, 110
    mdyy  111
    mdyyyy  112
    mmddyy  113
    mmddyyyy  114
    ngerman  115
    nodate  116, 117, 118
    nodayofweek  119, 120, 121, 122, 123
    oclock  124
    raise  125, 126
    short  127, 128
    text  129
    us  130
    yyyymmdd  131
\pdfdate  132
\pmname  133, 134
\pmstring  135, 136

Q \quarterpast  137
\quarterto  138

S SECOND counter  139
seminar package  140
\setdefaultdate  141
\settimeformat  142, 143
\shortdate  144, 145
\shortdayofweekname  146, 147
\shortmonthname  148, 149

T \textdate  150, 151, 152
\THEDAY  153, 154
\timeseparator  163, 164
\today  165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181
TOHOUR counter  182
TOMINUTE counter  183
\twodigit  184

U \usdate  185

Y \year  186
YEAR counter  187
\yyyymmdddate  188

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 le.

4To be more precise, \today is dened to be \formatdate{\day}{\month}{\year} where \longdate etc change the denition of \formatdate

5Thanks to Denis Bitouz for asking about this

6thanks to Uwe Bieling for supplying the German names