The reason it is confusing is that "had" is being used in two different ways. The first "had" is like "haber" in Spanish, the second is like "tener." Both "haber" and "tener" are "to have" in English.
But the structure is just the same, they work together the same way.
I hope my Spanish is correct here, I'm only intermediate in Spanish. I think
"I had had a good day" = "Yo había tenido un buen día" and
"I have had a good day" = "Yo he tenido un buen día."