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

For printed drafts of my papers, I would like to add a timestamp on every page with the date/time when the document was last compiled. Is there any LaTeX command that produces the current date/time at compile time? Even better, is there any package that already solves my problem?

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.

• Is there a version of \currenttime which comes from a standard class? I'm not sure if people have installed that package. I'll share my file. – Sigur Nov 28 '13 at 0:06
• they can install that package. Should be no problem. Having fancyhdr and datetime can't damage 8) – BlueWizard Dec 8 '16 at 12:14
• datetime is obsolete, you should use datetime2and the command for getting date and time becomes \DTMnow. – yannis Jan 29 '18 at 17:10

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}
\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)

• Thanks for the answer and example. It's a shame, though, that the version of datetime on TeX Live is outdated, as I can't reliably expect collaborators to also have the latest version. I'll have to hack my way through the older datetime. – Juan A. Navarro Aug 4 '10 at 11:01
• Thanks for the update! Hope you don't mind I cleaned up a bit your example for the older datetime so that it's less hackish. ;) – Juan A. Navarro Aug 4 '10 at 11:56
• @Juan A. Navarro: I guess I do have a bit of a tendency to go straight for the hack! \makeatletter is a bit of a give-away. I'll add here (rather than editing yet again) that, for this case, the obvious advantages of the newer version of datetime are: more formats and \currenttime includes seconds. – Loop Space Aug 4 '10 at 12:21

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

• How does this differ from the answer by @GrygoryM? – Ruben Jan 2 '17 at 17:15
• @Ruben It's a different package (datetime2 vs datetime). Technically it's not an update but a replacement (or alternative). @Betsalel, it might be worth expanding your answer to include an example with datetime2 commands (e.g. \DTMnow, \DTMcurrenttime). – Nicola Talbot Jan 2 '17 at 18:55
• @NicolaTalbot -- fair enough, but let's be frank. Does it add such novelty to say use the datetime2 macros instead of those from datetime? (pls: no offense @Betsalel, just trying to be honest.) In my opinion it's more a comment than an own answer. – Ruben Jan 3 '17 at 1:30
• when I added this yesterday I didn't have enough points to comment. I agree that it was only comment worthy. to note, when I started using the datetime package and looking the documentation up I was pointed to datetime2 which has more features. – Betsalel Williamson Jan 3 '17 at 16:04
• Shouldn't the datetime package be overwritten with the new and improved code instead of adding a new package? This is like a non-commited upgrade e.g. python2 and python3`. – Jonathan Komar Mar 1 '18 at 14:09