About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.


4.2.1 Changing the Format of \today

In the previous exercise, we used the \today command to produce the current date. By default, this command displays the date in US format. To illustrate how to use packages, this section will look at how to use the datetime package to change the way that \today displays the date.

The datetime package has various options that can be used to change the format of \today. For example, by default the datetime package redefines \today to display the date in the form: Tuesday 25th September, 2012. The option short will produce an abbreviated form, (for example Tue 25th Sep, 2012) and the option nodayofweek won't display the day of the week (for example 25th Sep, 2012). For those who don't like the raised ordinal, there is the level option. These can be passed as a comma separated list in the optional argument to the \usepackage command. It is also possible to use a declaration instead. For example, to redefine \today to display the date in the form 25/09/2012, you can either do

\usepackage[ddmmyyyy]{datetime}

or

The datetime package also defines the command

\currenttime

which displays the current time, where again the format can be changed by the package options. So the option 12hr will cause \currenttime to display the date in 12 hour format (for example, 2:38pm) and the option 24hr will cause \currenttime to display the date in 24 hour format (for example, 14:38).

Exercise 3: Using the datetime Package

Edit your document from Exercise 2 so that it uses the datetime package. Experiment with the different package options, for example

\usepackage[short,nodayofweek,level,12hr]{datetime}

and add the current time

This document was created on: \today\␣at \currenttime.

You can download or view an example. For a full list datetime of package options, see the datetime documentation.


This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs