We can tell by the stories that they took place at different times. Matthew has the birth of Jesus while Herod the Great was still king of Judea. That puts it at before 4 BCE. Luke has the birth of Jesus during the Census of Quirinius. We know when that was and it was in 6 CE. Some people try to claim that Luke also has the birth of Jesus during Herod's time, but if you read Luke 1 carefully you will see that there is only the prophecy of his birth then. To be honest the author of Luke probably wanted the birth to be during Herod's time, but he forgot his history. After all that was a good 80 years before the book was written.
It gets a bit detailed as I am examining it. So, because I am not a genius, I must go over details slowly and carefully as possible. So who was Quirinius? He was the Roman governor of Syria at the time of the census ordered by Caesar Augustus. That was why Jesus was born in Bethlehem. (Luke 2) I go slowly and don't like to argue, so if you have questions or a difference from what I am slowly writing, please let me know. But I am trying to go through the reasoning slowly.
So Luke chapter 2:1-7 says (English Standard Version) --
"In those days a decree went out from Caesar Augustus that all the world should be registered.
2This was the first registration when Quirinius was governor of Syria.
3And all went to be registered, each to his own town.
4And Joseph also went up from Galilee, from the town of Nazareth, to Judea, to the city of David, which is called Bethlehem, because he was of the house and lineage of David,
5to be registered with Mary, his betrothed, who was with child.
6And while they were there, the time came for her to give birth.
7And she gave birth to her firstborn son and wrapped him in swaddling cloths and laid him in a manger, because there was no place for them in the inn."
It isn't so easy for me to coordinate the scriptures so I have to go slowly, if possible. So Luke's account says that Jesus was born during the time Quirinius took a census.