How can I typeset the date/time at compile time?

One can use \today to get the current date, the command \currenttime from datetime package to get the current time, and fancyhdr package to add it to every page.


Expanding on Grigory's answer, here's a MWE. To get the date and time in a reasonable format, I found that I wanted the most recent version of datetime, which is dated 2010/02/06 (the version that is on my system - from TeXLive 2009 - is dated 2007). Using the default options for date and time format made the information too long (as it is, I decided it was better to shift the page number from the centre to the left).

\documentclass{article}
\usepackage{fancyhdr}
\usepackage[yyyymmdd,hhmmss]{datetime}
\pagestyle{fancy}
\rfoot{Compiled on \today\ at \currenttime}
\cfoot{}
\lfoot{Page \thepage}

\begin{document}
My great work.
\end{document}

If for some reason you can't use the 2010 version (or can't be sure that coworkers have it), a solution that works on the older datetime is as follows:

\documentclass{article}
\usepackage{fancyhdr}
\usepackage[us,12hr]{datetime} % `us' makes \today behave as usual in TeX/LaTeX
\fancypagestyle{plain}{
\fancyhf{}
\rfoot{Compiled on {\ddmmyyyydate\today} at \currenttime}
\lfoot{Page \thepage}
\renewcommand{\headrulewidth}{0pt}}
\pagestyle{plain}

\begin{document}
My great work.
\end{document}

This later version also keeps the pagestyle closer to the plain default, you can edit of course as you like. The date will also show as "ddmmyyyy" instead of "yyyymmdd" but that's probably fine for your needs.

(edited by Andrew in response to Juan's comment - I can't resist a challenge; and then edited again by Juan to improve the example)


There has been an update to the datetime package and it is now better to use: http://ctan.org/pkg/datetime2

Tags:

Datetime