Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an embarrassingly basic modular arithmetic question. I understand that I can subtract, for example, 1 hour from 10 o'clock to get 9 o'clock, or even 2 hours from 1 o'clock to get 11 o'clock; but how do I subtract 2 o'clock from 11 o'clock to get 3 hours.

That is, I want a function that takes two times on the face of a clock, and gives me the interval between them.

For example: I have two angular values measured in "hours". One value is the right ascension of the apparent sun, $\alpha(t)$, while the other is the right ascension of the "mean sun", $\langle\alpha\rangle(t)$; both are mod 24. I'm interested in the angular difference between these two values $$E(t) = \langle\alpha\rangle(t) - \alpha(t)$$ Is this just inherently ambiguous, so that I need to impose some additional constraint based on information about the system (e.g., here that the values can be positive or negative, and are always small, so that, say $\pm 22$ should be interpreted as $\mp 2$), or is there some simple systematic way to ensure that I get the correct values?

share|cite|improve this question… check this answer – iostream007 May 11 '13 at 16:50
up vote 4 down vote accepted

Just subtract. Your answer will only be well-defined mod 12 (because maybe 15 hours passed between 11 and 2 o clock). If you want a "canonical" answer, you can always take the least residue mod 12. In this case, we get $(2 - 11) = -9 = 3.$

In fancy language, the times on a clock are a torsor for $\frac{\mathbb{Z}}{12}$. John Baez has a great blog entry on this.

share|cite|improve this answer
@Jean-Sébastien: I've added an example of my application to make things a bit more concrete. – raxacoricofallapatorius Nov 19 '12 at 20:01

2 o'clock - 11 o'clock = -9 = 3 mod 12 ?

share|cite|improve this answer

$$ 2-11=-9\equiv 3 \mod 12 $$ you can take the absolute value of that, or work with the $24$ hours format and use the fact that $2$ is also $14$ and then have $$ 14-11=3 $$

share|cite|improve this answer
I think I need a nap... :-S – amWhy Nov 19 '12 at 19:17
@amWhy you only needed to add the fact that we work mod $12$ – Jean-Sébastien Nov 19 '12 at 19:17
I saw that others already covered that...I knew what I was thinking, but that's hardly the same as being clear and explicit in the first place! (+1) by the way! – amWhy Nov 19 '12 at 19:36
@amWhy I'd be down for a nap as well, great idea ;). I like the 24 hours format for that kind of thing. Obviously you could argue that the problem comes back if you want ot know the time difference between say $23$ hours and $2$ but that is equivalent to $11$ and $14$ anywya so – Jean-Sébastien Nov 19 '12 at 19:46

If you just have times with no dates attached, you can't tell +2 from -22. You can choose to have the result be in the range $[-12,+12)$ or any other range of length $24$ like $(-5,19]$ that you like. Based on what you day, I would opt for one centered at zero.

share|cite|improve this answer

What you're doing is also a problem in directional statistics with measuring angles.

If the times are $t_1$ and $t_2$, then I think you want

\begin{cases} |t_1 - t_2| & \text{If}\; |t_1 - t_2| \le 12\\ 24 - |t_1 - t_2| & \text{If}\; |t_1 - t_2|>12 \\ \end{cases}

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.