Two years ago, Barack Obama was a damaged-goods, lame-duck president who had just endured his second consecutive midterm drubbing — thanks in large part to Republican efforts to tie Democrats to him and his eponymous health-care law.

Today, Obama is virtually tied for first place in a new poll of the greatest modern president.

The Quinnipiac University poll indicates 29 percent say Obama is the greatest president since World War II — just shy of the 30 percent who cite Ronald Reagan, the long-standing titleholder.

That's a vast improvement for Obama, who back in July 2014 was viewed as the greatest modern president by just 8 percent.

A big reason Obama has surged is that he has now gobbled up a bigger portion of the greatest-Democratic-president pie. The percentage saying the greatest modern president is Bill Clinton has dropped from 18 percent in 2014 to 9 percent. The number citing John F. Kennedy is down from 15 percent to 12 percent. Harry S. Truman and Lyndon B. Johnson dropped 2 points and 1 point, respectively.

But Obama also seems to have gobbled up some of the GOP's pie. Reagan dropped from 35 percent in 2014 to 30 percent today, and the GOP's share of the overall greatest-modern-president piece has dropped from 46 percent to 38 percent. Democrats, meanwhile, have risen from 50 percent to 56 percent.

Part of it is almost certainly proximity. Obama is just days removed from office, and perhaps that gives him a bump. He's also perhaps helped by the fact that the last Democratic president before him left office 16 years ago, and that president's wife just suffered a pretty bad defeat. The Clinton brand just isn't what it once was.

That proximity also hurts Obama when it comes to the worst modern president, which Quinnipiac also polled. For that honor, Obama (23 percent) is virtually tied with Richard Nixon (24 percent) and George W. Bush (22 percent) at No. 1. But even there he's improved; back in 2014, he was clearly the No. 1 worst modern president, with 33 percent saying so.

In other words, the polarized views of Obama certainly come into play here.

But Obama has also done himself plenty of good in recent months. As Americans were choosing between two candidates they didn't particularly like in the 2016 election, he suddenly saw a marked increase in popularity — even as not much was truly accomplished in Washington — and he exited with his best approval ratings since his first year in office, according to some polls.

The true measure of a president's legacy, it bears noting, isn't really measured six days after he leaves office, and these numbers are bound to shift around in the years to come.

But the early reviews of Obama's presidency are certainly better than we could have foreseen two years ago.