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 GOP 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 he’s surged is that Obama 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 Truman and Lyndon 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.