Tx · LaTeX & TikZ

How to Typeset a Time of Day or Duration with siunitx

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose the meaning

    Decide whether the value is a clock reading, such as 13:05, or a duration, such as 2 hours and 30 minutes.

  2. 2. Use the right tool

    Use datetime2 for clock readings; use siunitx quantities for durations expressed with units.

  3. 3. Format consistently

    Choose a clock style or unit presentation that matches the conventions of your document.

A clock reading such as 13:05 and a duration such as 2 hours 5 minutes may look similar, but they represent different things. siunitx is intended for numbers and quantities with units, not for parsing clock notation. Use a date-and-time package for a time of day, and use siunitx when you want to express a duration as a measured quantity.

For a time of day, use datetime2

The datetime2 package provides \DTMdisplaytime for typesetting a time from hour, minute, and second fields. A minimal example is:

\documentclass{article}
\usepackage{datetime2}

\begin{document}
The meeting starts at \DTMdisplaytime{13}{05}{00}.
\end{document}

The package applies its configured date-and-time style, so the displayed form can depend on the selected style or locale. This is useful when you want consistent formatting throughout a document. For instance, documents may use a 24-hour clock or a 12-hour clock with an AM/PM marker.

If you only need one uncomplicated clock reading, ordinary text is also fine: 13:05. A colon-separated clock value is a notation, not a numeric quantity that siunitx should parse.

For a duration, use siunitx quantities

A duration is a quantity of time. With siunitx version 3, write each value with its unit using \qty:

\documentclass{article}
\usepackage{siunitx}

\begin{document}
The experiment lasted \qty{2}{\hour} and \qty{30}{\minute}.
\end{document}

The unit commands \hour, \minute, and \second let siunitx format the units consistently with the rest of your document. You can also write a duration using a single unit when appropriate—for example, \qty{9000}{\second}. Choose a representation that makes the scale easy for your readers to understand.

Older siunitx documents commonly use \SI{...}{...} for a number with a unit. In current version 3 documents, \qty{...}{...} is the corresponding quantity command. Avoid mixing old and new command styles without a reason, especially if you need the source to work with a particular package version.

Why a colon-separated value does not fit siunitx

A string such as 13:05 is not a decimal number with a unit. It encodes separate fields—hours and minutes—and the colon is part of the time notation. Consequently, putting it inside \qty{...}{...} or \SI{...}{...} is not the intended use and may produce a parsing error.

The distinction matters even more for durations. 02:30 might mean two hours and thirty minutes, two minutes and thirty seconds, or a clock time, depending on context. If you use colon notation for a duration, define the convention for readers and typeset it as text rather than treating it as a single siunitx number. For technical writing, explicit units often remove the ambiguity: “2 h 30 min.”

A complete example using both packages

This example uses datetime2 for a clock reading and siunitx for an elapsed duration:

\documentclass{article}
\usepackage{siunitx}
\usepackage{datetime2}

\begin{document}
The measurement began at \DTMdisplaytime{13}{05}{00} and lasted
\qty{2}{\hour} and \qty{30}{\minute}.
\end{document}

The packages have separate roles: \DTMdisplaytime formats the time of day, while \qty formats each duration quantity. This separation also makes the meaning of each value clearer in the source.

Common mistakes

  • Putting a clock reading in \qty or \SI. These commands expect a number and a unit, not hour-and-minute fields separated by a colon.
  • Using a clock-time formatter for elapsed time. A time-of-day command represents a position within a day; a duration represents an amount of elapsed time. Use units for the latter.
  • Leaving the duration convention implicit. If you write something like 02:30 for a duration, say whether it means hours and minutes or minutes and seconds. Explicit units are usually clearer.
  • Mixing package versions’ command conventions. For siunitx version 3, prefer \qty; older examples may show \SI.

References

  1. The siunitx package documentation
  2. The datetime2 package documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.