Image copyright Hulton Archive/Getty Images Image caption Franklin Roosevelt holds a record of 12 years in office as US president

At precisely midday in Washington on 20 January, Barack Obama's eight years as US president will end.

Mr Obama will join 11 previous two-term presidents in a dead heat as the nation's second longest serving head of state.

They include:

Thomas Jefferson (president from 1801 to 1809)

James Madison (president from 1809 to 1817)

James Monroe (president from 1817 to 1825)

Andrew Jackson (president from 1829 to 1837)

Ulysses Grant (president from 1869 to 1877)

Grover Cleveland (president from 1885 to 1889 and 1893 to 1897)

Woodrow Wilson (president from 1913 to 1921)

Dwight Eisenhower (president from 1953 to 1961)

Ronald Reagan (president from 1981 to 1989)

Bill Clinton (president from 1993 to 2001)

George W Bush (president from 2001 to 2009)

But each of these men trails Franklin Roosevelt, whose record of 12 years in office (1933-45) preceded the introduction of two-term limits.

Is it possible to find a way of breaking this 12-way tie for second place?

A combination of clock tampering, delayed oath taking, constitutional amendments, medical procedures and the slowing of the earth's rotation around the sun means that each of the second place presidents has exercised his powers for a different amount of time.

The Clock and the Oath

There are two ways to calculate the length of a president's service: the clock and the oath.

The clock is the date and time that the law fixes for the start and end of a president's term.

Image copyright AFP Image caption Preparations are now well under way for Donald Trump's swearing in

Image copyright Hulton Archive Image caption Chief Justice John Marshall argued the new president could be sworn in any time after after midnight on polling day

The oath is the 35-word sentence that the new president must swear before he enters "on the Execution of his Office".

The clock makes the president. The oath allows him to use the powers of the office.

Until 1933, the clock was set at the 4 March following the previous November's election. Frustratingly for our purposes, the 1792 Presidential Succession Act made no mention of an exact time of day for the transfer of power.

In 1821, Chief Justice John Marshall suggested that the new presidential term began at the stroke of midnight. But this was incredibly inconvenient. Either the country would have to stay up until midnight to watch the new man take office, or everyone could go to bed at a normal time and the president-elect would become president in his sleep.

He would also need to take the oath. The chief justice insisted that the new president might be sworn in at anytime after midnight.

"Undoubtedly, on any pressing emergency the President might take the oath in the first hour of the 4th of March," Marshall wrote, "but it has never been thought necessary so to do, and he has always named such hour as he deemed most convenient."

By convention, this hour was noon on the 4 March. It seemed logical to let the outgoing president hold onto his office until then. The clock and the oath could both wait.

Clock Tampering

It is often hard to work out the exact time of the start of the president's term in the 19th Century.

Image copyright Hulton Archive Image caption Grover Cleveland was the 22nd and 24th president

On inauguration day on 4 March 1889, business was running late. At 11.52am, President-elect Harrison and outgoing President Cleveland had yet to enter the Senate chamber. So, Senators resorted to an old trick.

"Old Capt Bassett therefore went up to the clock and with a long stick deliberately turned the minute hand back 10 minutes. A storm of laughter greeted this time-honored method of cheating Old Father Time."

In this way, the US Capitol managed to live in two time zones - real time and Senate time.

This clock tampering makes calculations from this era impossible to make with any degree of accuracy. In the absence of better evidence, we are forced to declare an unsatisfactory honorary tie for the first six presidents on our list.

After that, calculations get easier.

Woodrow Wilson

Image copyright Hulton Archive Image caption Woodrow Wilson around 1916

The end of clock tampering and the advent of a more officious standard of time-keeping in the 20th Century makes it simpler to measure presidential term lengths.

On 4 March 1913, Woodrow Wilson took the oath of office at 1.10pm- some 70 minutes beyond midday. By contemporary standards, this was an unremarkable delay.

Eight years later, Wilson had the chance to make up these minutes by stringing out his successor Warren Harding's inauguration.

But Wilson, who was still suffering from the effects of a major stroke, decided to leave Capitol Hill shortly before Harding's swearing in. At 11.55am, Wilson was driven home.

Perhaps this final act was a micro-abdication. Warren Harding himself was not officially sworn in until 1.18pm. Woodrow Wilson had given up the chance to make up for his lost time.

Wilson total: Eight years minus 1 hour, 10 minutes

New timings came into play

By 1933, America was getting rather fed up with the lengthy four-month transition period between presidential election and presidential inauguration.

Image copyright Getty Images Image caption Details of the transfer of power from one president to the next are to be found in the US constitution

So the constitution was amended in order to move up the start of the next president's term and to fix with precision the midday transfer of power: "The terms of the President and Vice President shall end at noon on the 20th day of January… and the terms of their successors shall then begin."

"The president-elect, by dint of the explicit command of the Twentieth Amendment, legally becomes president at the precise stroke of noon on January 20," writes Professor Akhil Reed Amar in his book America's Unwritten Constitution.

He argues that it is "the clock, not the oath, that does the work".

Despite this, the oath continues to be the centrepiece of all inauguration ceremonies. There is no countdown clock to the 12pm assumption of the office, a moment which often passes unnoticed.

In 1937, Franklin Roosevelt was the first president to be affected by the new timings. His four successive election victories later provoked his Republican opponents into passing the 22nd Constitutional Amendment restricting presidents to two terms.

Dwight Eisenhower

Image copyright Hulton Archive Image caption President Eisenhower addressing the UN in 1953

By law, Dwight Eisenhower's presidential term began at 12pm on 21 January 1953. But he wasn't sworn in until 12.32pm. During this gap, Eisenhower was legally president, but he wasn't yet able to exercise the powers of his office. We therefore deduct 32 minutes from his total.

Eisenhower total: Eight years minus 32 minutes.

Two more factors

Post-Eisenhower, the precise timings of presidential powers were affected by two separate developments.

Firstly, in 1967, the constitution was changed again. The 25th Amendment laid out the procedure by which a president might temporarily transfer his powers to his vice president.

Secondly, in 1972, occasional leap seconds were introduced worldwide in order to compensate for the earth's slowing rotation around the sun.

Ronald Reagan

Image copyright Hulton Archive/Getty Images Image caption Ronald Reagan in the White House in 1985

Mr Reagan shrewdly avoided losing early minutes of power by putting the oath before the clock. He was sworn in at 11.57am. Three minutes later, he inherited both the office and the powers of the presidency.

On 13 July 1985, Ronald Reagan went to hospital for a colon operation. As a precaution, he handed over his powers to Vice President George HW Bush for eight hours. Although Reagan was still president during this period, he was unable to exercise the powers of his office, so we deduct the eight hours from his total.

There may be some consolation for Mr Reagan in the five leap seconds he accrued during his two terms. It's not clear how he spent them.

Reagan total : Eight years minus 7 hours, 59 minutes, 55 seconds

Bill Clinton

Image copyright AFP Image caption Bill Clinton - benefited from extra seconds

Mr Clinton followed Mr Reagan's example in being sworn in early - in his case at 11.58am. He survived impeachment, never handed over his powers to his vice president, and benefited from five leap seconds.

Clinton total : Eight years plus 5 seconds

George W Bush

Image copyright AFP Image caption George W Bush lost time in office because of medical complications

Mr Bush was sworn in at 12.01pm - losing only one minute of the exercise of his presidential powers.

He twice invoked the 25th Amendment, for minor surgery in 2002 and 2007. Each time, Mr Bush's powers went to Vice President Dick Cheney. On the second occasion, Mr Cheney couldn't resist documenting his temporary promotion. He wrote a letter to his grandchildren and helpfully signed it "Richard B. Cheney, Acting President of the United States, (Grandpa Cheney)".

In all, George W Bush transferred the powers of his presidency for a total of four hours and 20 minutes. His only compensation was a meagre two leap seconds.

George W Bush total : Eight years minus 4 hours, 20 minutes, 58 seconds

Barack Obama

Image copyright AFP Image caption Mr Obama required a presidential repeat of oath on the day after polling day in 2009

Everyone missed the moment in which Barack Obama became America's first black president.

At the stroke of midday on 20 January, guests at his inauguration were busy watching a quartet of musicians perform the composition Air and Simple Gifts. Mr Obama took up his position as America's head of state whilst he was craning his neck, trying to get a good view of the musicians playing behind him.

By contrast, the White House website dutifully followed the clock to the second. On the stroke of noon, President Bush's homepage was replaced by President Obama's homepage.

But Mr Obama had to wait another five minutes before he could exercise his powers. At 12.05pm, the Chief Justice, John G Roberts, addressed the new head of state by his old job title, "Are you prepared to take the oath, Senator?"

Memorably, the chief justice and the president then proceeded to ham fist their way through the simple oath - forcing a re-do the next day. We'll count Obama's exercise of power from his first oath.

For his eight years in office, Barack Obama only gets three leap seconds.

Obama total : Eight years minus 4 minutes, 57 seconds

The Winner is… (drum roll)

Excluding the first six presidents who lived in an age of inaccurate time-keeping and occasional clock tampering, the final table is as follows:

1) Bill Clinton: Eight years plus 5 seconds

2) Barack Obama: Eight years minus four minutes, 57 seconds

3) Dwight Eisenhower: Eight years minus 32 minutes

4) Woodrow Wilson: Eight years 8 minus one hour, 10 minutes

5) George W Bush: Eight years minus four hours, 20 minutes, 58 seconds

6) Ronald Reagan: Eight years minus seven hours, 59 minutes, 55 seconds

So, Bill Clinton wins the unofficial contest for second place by a little over five minutes. This may provide some degree of micro-consolation as he watches the man who defeated his wife take office on 20 January.

In order to beat Clinton's record, Mr Trump must hope for re-election, perfect health and a slowing earth.