The dating of Matthew is not easy to figure out. These documents do not come with a date. Therefore, we need to do a little detective work. What we know for certain is that Ignatius, an early church father, quoted Matthew in the early second century. So, we know that it was written before Ignatius. If we make a few educated guesses we might be able to bring down the date further.
First, the early church held that the gospel of Matthew was one of the earliest gospel ever written. If we take the ancient evidence seriously, then Irenaeus dates Matthew before Mark.
Second, there seems to be some references that the temple was still standing. For example, in Matthew 17:24, there is a story of paying temple taxes. This would mean that the date was before 70 A.D.
Third, there is an indirect method of dating Matthew. There are no references to the works of Paul. This may mean that the gospel was written before Paul.
In the end, the dating of Matthew is not a precise science, but through educated guesses we can make some good advances.