OH MAN! I *DO* apologize!
I actually had *NOT* seen your post from today!
I had looked at the thread earlier in the day and realized I had a typo in the code I showed you. So I fixed it and then checked to make sure it worked.
And then I got to thinking about the problem and realized that the hard part was that, as I had mentioned, you need a zero-based number of days when dividing by years but you want a 1-based number of days for the days in months. That's when I hit on doing
Code:
var quads = Math.floor( (nDays-1) / 1461 ); // 1461 days in 4 years
nDays -= quads * 1461;
It was more a matter of surrendering to my own stubborness than anything else.
Even AFTER I posted I didn't scroll up and see your post with the right answer!
PLEASE...it was just blindness and my own stubbornness at finally understanding the meat of the problem that drove me to write the code.
I have *STILL* not tested your answer. I am assuming it works and you have tested it.
And here I was so happy at myself for coming up with that "quads" trick.