Sahih Bukhari, Volume 4, Book 55, Number 585:
Narrated Abu Dhar:
I said, "O Allah's Apostle! Which mosque was first built on the surface of the earth?" He said, "Al-Masjid-ul-Haram (in Mecca)." I said, "Which was built next?" He replied "The mosque of Al-Aqsa (in Jerusalem)." I said, "What was the period of construction between the two?" He said, "Forty years." He added, "Wherever (you may be, and) the prayer time becomes due, perform the prayer there, for the best thing is to do so (i.e. to offer the prayers in time)."
See also Vol. 4, No. 636 with a different concluding remark, but essentially the same narration for the part concerning the "historical information".
In rought estimates, Abraham lived about 2000 BC, and Solomon about 950 BC. According to Muhammad Abraham built the Kaaba (Bukhari, Vol. 4, No. 584), calling its original or true foundations "the foundations of Abraham" (Vol. 5, No. 587). That Abraham ever went to Mecca is contrary to Biblical records, and none has been able to give me any historical confirmation of this claim. Whether this is true or not is, however, irrelevant for our observation. It is only important that Muhammad believed it to be true. It was Solomon who built the first temple in Jerusalem.
This is obviously not a difference of 40 years, but a difference of over 1000 years. Even though this is not a Qur'an contradiction I have included it here since it gives additional evidence from the Hadith that the feature of historical time compression that is observed in many Qur'anic passages was a characteristic of Muhammad's mind and can also be seen in his other pronouncements outside the Qur'an.
See also The Farthest Mosque?
Contradictions in the Qur'an
Answering Islam Home Page