Murphy's Law says if something can go wrong, it will go wrong. But then there's Joseph's Law: if something goes wrong, God is behind the scenes making it right (see Romans 8:28). That was Joseph's perspective, even when it seemed like he took two steps forward and three steps backward. One day he was the favorite son of his father and got a dream from heaven; the next day he was sold by his own brothers into slavery in Egypt. While there he climbed to the top of Potiphar's household, only to reject the advances of Potiphar's wife, be accused of rape, and be thrown into prison under false accusation.
That's where we find Joseph in Genesis 40. Yet even there, God was at work behind the scenes: the captain of the guard put Joseph in charge of the jailed butler and baker of the king of Egypt. In the course of their custody, these two men each had a dream, which Joseph interpreted: the baker's days were numbered, but the butler would soon be restored to Pharaoh's household. "But," Joseph said to the butler, "remember me when it is well with you, and please show kindness to me; make mention of me to Pharaoh, and get me out of this house" (v. 14).
Sure enough, both dreams came to pass, "yet the chief butler did not remember Joseph, but forgot him" (v. 23)—for two whole years. Now, why did God allow Joseph to stay in prison for two years? I think it's safe to say He was putting some finishing touches on Joseph. Joseph started out pretty naïve and spoiled, but God was working something deep in his life—like humility and a heart of trust.
At the end of those two years, Pharaoh had two troubling dreams that called for Joseph's unique skill set. At this point, the butler remembered Joseph, who was summoned and interpreted Pharaoh's dreams: Egypt would face seven years of plenty and seven years of famine. Then something extraordinary happened: Pharaoh put Joseph in an incredible position of power to help prepare for the famine (see Genesis 41:40-41).
When you're down in the muck, it's hard to think, Wow, God has something great in store! But you have no idea what God is preparing you for right now in the midst of your trials as He molds and shapes you more and more into the image of His Son (see Romans 8:29).
It's really a shame if painful, hurtful times don't serve to change you. Because then all you can say looking back is, "Gosh, that was horrible." If you don't grow through hard times, that's such a wasted opportunity. God wouldn't allow that to come into your life unless He wanted to teach you a lesson and change you. So find out what the Lord is trying to show you in whatever situation you're in and learn from it, finding encouragement in the example of Joseph.