Short answer
The Quran does not give the age of the earth. It says Allah created the heavens and earth in six "days" (ayyam), and it uses "day" elsewhere for a thousand or even fifty thousand of our years, so many scholars understand these as periods, not 24-hour days. The scientific estimate of about 4.5 billion years does not contradict the Quran.
This is a question of belief and knowledge, not fiqh. A Muslim must believe that Allah created everything and that the creation was in six days as He said. The length of those days and the age of the earth are not stated, so no fixed number is part of the faith.
The four schools agree on this.
Explanation
Several ayat say Allah created the heavens and the earth in six days (7:54 and others). Surah Fussilat gives more detail: the earth in two days, its mountains and provisions completing four, and the seven heavens in two (41:9 to 12).
What does "day" mean here? The Arabic word yawm can mean a day or a stage. The Quran itself says that a day with your Lord is like a thousand years of your counting (22:47; 32:5), and speaks of a day whose length is fifty thousand years (70:4). Before the sun and earth existed there was no 24-hour day to count. For these reasons many classical and modern commentators understand the six days as six periods whose length only Allah knows.
Science and the Quran. Geologists estimate the earth is about 4.5 billion years old, and the universe older still. The Quran does not set a number, so there is no clash. Muslims should not tie the Quran to a scientific figure that may later change, nor reject sound findings that do not contradict revelation. The Quran also says the heavens and earth were once joined and then separated (21:30), see Quran 21:30.
What about hadith that list the days of creation? There is a narration in Sahih Muslim describing what was created on each day of the week. Scholars such as al-Bukhari and Ibn Kathir discussed problems in it, and it does not fix the earth's age either. Ask a scholar if you want to study it.
See also space and the universe in Islam and the seven heavens.
The evidence
Quran, Surah Al-A'raaf 7:54
إِنَّ رَبَّكُمُ ٱللَّهُ ٱلَّذِى خَلَقَ ٱلسَّمَٰوَٰتِ وَٱلْأَرْضَ فِى سِتَّةِ أَيَّامٍۢ ثُمَّ ٱسْتَوَىٰ عَلَى ٱلْعَرْشِ يُغْشِى ٱلَّيْلَ ٱلنَّهَارَ يَطْلُبُهُۥ حَثِيثًۭا وَٱلشَّمْسَ وَٱلْقَمَرَ وَٱلنُّجُومَ مُسَخَّرَٰتٍۭ بِأَمْرِهِۦٓ ۗ أَلَا لَهُ ٱلْخَلْقُ وَٱلْأَمْرُ ۗ تَبَارَكَ ٱللَّهُ رَبُّ ٱلْعَٰلَمِينَ ﴿٥٤﴾
Indeed, your Lord is Allah, who created the heavens and earth in six days and then established Himself above the Throne. He covers the night with the day, [another night] chasing it rapidly; and [He created] the sun, the moon, and the stars, subjected by His command. Unquestionably, His is the creation and the command; blessed is Allah, Lord of the worlds.
Creation took six days.
Quran, Surah Al-Hajj 22:47
وَيَسْتَعْجِلُونَكَ بِٱلْعَذَابِ وَلَن يُخْلِفَ ٱللَّهُ وَعْدَهُۥ ۚ وَإِنَّ يَوْمًا عِندَ رَبِّكَ كَأَلْفِ سَنَةٍۢ مِّمَّا تَعُدُّونَ ﴿٤٧﴾
And they urge you to hasten the punishment. But Allah will never fail in His promise. And indeed, a day with your Lord is like a thousand years of those which you count.
A Quranic day is not always 24 hours.
Quran, Surah Al-Ma'aarij 70:4
تَعْرُجُ ٱلْمَلَٰٓئِكَةُ وَٱلرُّوحُ إِلَيْهِ فِى يَوْمٍۢ كَانَ مِقْدَارُهُۥ خَمْسِينَ أَلْفَ سَنَةٍۢ ﴿٤﴾
The angels and the Spirit will ascend to Him during a Day the extent of which is fifty thousand years.
The Quran uses day for very long periods.
Quran, Surah Fussilat 41:9-10
۞ قُلْ أَئِنَّكُمْ لَتَكْفُرُونَ بِٱلَّذِى خَلَقَ ٱلْأَرْضَ فِى يَوْمَيْنِ وَتَجْعَلُونَ لَهُۥٓ أَندَادًۭا ۚ ذَٰلِكَ رَبُّ ٱلْعَٰلَمِينَ ﴿٩﴾ وَجَعَلَ فِيهَا رَوَٰسِىَ مِن فَوْقِهَا وَبَٰرَكَ فِيهَا وَقَدَّرَ فِيهَآ أَقْوَٰتَهَا فِىٓ أَرْبَعَةِ أَيَّامٍۢ سَوَآءًۭ لِّلسَّآئِلِينَ ﴿١٠﴾
Say, "Do you indeed disbelieve in He who created the earth in two days and attribute to Him equals? That is the Lord of the worlds." And He placed on the earth firmly set mountains over its surface, and He blessed it and determined therein its [creatures'] sustenance in four days without distinction - for [the information] of those who ask.
The stages of the earth's creation.
Where the ruling is recorded
- Tafsir Ibn Kathir, Commentary on Surah al-A'raf 7:54 and Surah Fussilat 41:9 to 12. Discusses the six days and the order of creation.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.