Per the screenwriter Danny Rubin's answer here
Allow me to jump in here. Hi everyone. As mentioned above my original intent was that Phil would live for longer than a single lifetime. That was the point of the original script: to see how a person might change if he lived longer than one lifetime (it was always about a man who could not escape life). The studio felt that the loop shouldn't last longer than two weeks. They were afraid the audience would freak out if it lasted any longer. Because my bookcase calendar (also mentioned above) was a specific record of passing time, Harold chose to remove it from the script, and in that way he could tell the studio it lasted two weeks or whatever and nobody could point to anything in the script that contradicted that. This explains why the length of Phil's incarceration strikes so many as a mystery: it was designed to be a mystery. Still, the sensibility of the characters as they progressed I think required a guiding clock, and Harold provided that. His sense was that it lasted about ten years, and I think the movie reflects that sensibility.
According to the screenwriter, there are multiple answers. The studio says 2 weeks. That's unrealistic considering the 40 or odd days we see on screen. According to him, it's over a lifetime, so 70~100 years minimum for a normal human life span. For Director Harold Ramis, a "sense" of 10 years. 10 years is long enough for a man to change and learn everything we see him learn.
But as the screenwriter says, it's open ended. There is no singular correct answer, it's to the viewer to decide.
Screenwise, Phil spent 38 days that we can see, giving us a bare minimum. Since they were very careful to leave no clues, there is nothing to say if he spent just 39 days or 1000. As he had to master piano and dance and some other skills that take years of dedication to learn, a decade seems like a good imagined minimum.