(Note: for a short history of Christmas, and my view on whether the church should celebrate it, see here).
Popular Christmas folklore depicts the magi arriving at the manger in Bethlehem to pay homage and offer gifts to the newborn king, Jesus. This heartwarming story is reenacted countless times every year in Christmas plays. In contrast, another story from the Gospels' infancy narratives, namely the story of baby Jesus' encounter with the prophet Simeon and the prophetess Anna in the temple in Jerusalem, seems to receive little attention in Christmas observance.
The interesting thing is that an examination of the Gospel accounts makes it apparent that the visit of the magi occurred after the trip to the temple - perhaps even several months later!
The visit of the magi is recorded only in Matthew, while the trip to the temple for purification is found only in Luke, which makes it difficult to determine which occurred first. However, there are a number of clues that can assist us.
Firstly, Matthew does not say that the magi came to a manger or even to an inn, but to a house (Matthew 2:11). This suggests that by this time Mary and Joseph were no longer at the inn, which would rule out the magi having come on the very night of Jesus' birth.
Secondly, based on Herod's discussions with the wise men, he seems to have reckoned that Jesus might have been as old as two years by the time he gave the order to massacre the baby boys of Bethlehem (Matthew 2:16). While Herod in his cruelty might well have estimated conservatively to maximize his chances of killing the young king, his estimate of two years still makes it likely that Jesus was at least a few months old by this time. This would place the visit of the magi after the visit to the temple, which can be dated precisely to 41 days after Jesus' birth (eight days until circumcision and an additional 33 days for Mary's purification as prescribed in Leviticus 12:1-7). We cannot assume that they traveled exactly on the 41st day, but being faithful Jews they would surely not have delayed the trip more than a day or two beyond that.
Thirdly, the Law stated that the mother should bring a lamb and a pigeon or turtledove to offer. If she was unable to afford a lamb she could bring two pigeons or two turtledoves (Leviticus 12:8). Mary brought two turtledoves, indicating that she and Joseph were too poor to afford a lamb. However, if the magi had already come with their expensive gifts of gold, incense and myrrh, surely Mary and Joseph would have been able to afford a lamb.
Fourthly, Matthew's account tells us that "when they had gone", an angel appeared to Joseph in a dream and warned him to take the family to Egypt (Matthew 2:13-14). That they left during the night suggests that their departure was immediate. Theoretically there could have been time for a trip to the temple between the departure of the magi and Joseph's dream; however it seems unlikely that God would have allowed this trip knowing that Herod sought the child's life. It is certainly inconceivable that a trip to the temple could have taken place after Joseph's dream since this would entail blatant disregard for the angel's instructions to take flight.
In summary, there is ample evidence to support the conclusion that the trip to the temple took place about six weeks after Jesus' birth, and that the visit of the magi and consequent flight into Egypt took place at some point thereafter, perhaps as late as the second year of Jesus' life.
The one significant difficulty with this chronology is that Luke reports that "When Joseph and Mary had done everything required by the Law of the Lord, they returned to Galilee to their own town of Nazareth" (Luke 2:39). If the visit of the magi in Bethlehem was still in the future at this point, why does Luke have the family returning to Nazareth?
Like Matthew, Luke was aware that Jesus was born in Bethlehem but raised in Nazareth. Unlike Matthew, however, Luke seems not to have been aware of the visit of the magi or the flight into Egypt. Since Luke had no other events to place between the temple purification and Jesus' upbringing in Nazareth, it was only natural to transition the narrative by having the family return from the temple to Nazareth.
Luke has not made any statement that should cause us to doubt his historical credibility or indeed his divine inspiration. He has simply omitted information that was not available to him, and joined together as smoothly as possible the material that was available to him.
The conclusion we have reached has implications for the celebration of Christmas. If the visit of the magi is close enough in time to Jesus' birth to be celebrated at Christmas (and I certainly have no objection to this), then the visit of the holy family to the temple ought also to be celebrated at Christmas. In particular, the canticle of Simeon, the so-called Nunc Dimittis (Luke 2:29-35) is theologically rich and contains a veiled link between the Christmas story and the greater story of the cross. I would love to see this passage gain a more prominent place in the church's observance of Christmas.