Yosef's Freedom and Peretz's Birth
Yosef Hatzaddik was 17 when he was sold. He was 30 when he was freed. A difference of 13 years. When he revealed himself to the brothers, he was 39.
Many are bothered by the chronology of the Yehuda and Tamar story. Rashi says that Yehuda went to marry Bat Shua right after the selling of Yosef. This presents a difficulty since Yehuda had to have married, have children who were of marriageable age, then wait a bit, then have relations with Tamar, have Peretz, and Peretz had to have married and father 2 children all in the span of 22 years.
The Ibn Ezra answered it by disagreeing with Rashi and said that the story with Yehuda had happened earlier than the sale of Yosef, but this presents its own problems, such as why Yehuda was with the brothers during the sale.
The Seder Olam Rabba (using the Gr"a's Girsa) provides the chronology of how all the above fit into 22 years:
|Event||Running Year Count|
|Yehuda marries Bat Shua||0|
|1 year later, Er is born||1|
|7 years later, Er marries Tamar||8|
|1 year later, Er dies and Onan performs Yibum||9|
|1 year later, Onan dies [YY-I think this is what it means]||10|
|1 year for Tamar to stay as a widow in her father's house (verse 11)||11|
|1 year for "Vayirbu Hayamim" (verse 12) when Bat Shua died||12|
|1 year later, Peretz is born||13|
|7 years later, Peretz marries||20|
|1 year later, Hetzron is born||21|
|1 year later, Hamul is born||22|
We see that on year 13, the same year that Yosef was freed from prison (the rise of Mashiah ben Yosef), Peretz was born (the rise of Mashiah ben David).
However, it seems that somewhere, we're a year off. Seder Olam Zuta says that Peretz and Zerah were born in 2228, while we know that Yosef was freed in 2229 since Yaakov was 91 at Yosef's birth and
Yaakov was born in 2108, and at the time of his freedom, Yosef was 30.
Perhaps, we can say that we know from the gemara that Yosef was freed on Rosh Hashana of 2229, so it wasn't much later. צ"ע.
But even so, it could fit well with a midrash (that I mentioned previously):
Before the first oppressor was "born", the final redeemer was born.
Perhaps, we could say that Par'o was the same Par'o as the one in Shemot - and he did not care to remember Yosef - so he is considered the first oppressor. He was "born" as the oppressor when Yosef came out of prison to be his viceroy (as that is when the oppressor and ancestor of the oppressed first met). So, before the first oppressor was "born", the final redeemer - Peretz (the ancestor of Mashiah) - was born.