According to verse 7 of Chapter Hud, God is He Who created the heavens and the earth in six periods. As per the above verses, the heavens and the earth were created in six days. However, according to some other verses of the Quran, the heavens and the earth were created in two, four or eight days:
"Say: Is it that ye deny Him Who created the earth in two days and do ye join equals with Him? He is the Lord of (all) the Worlds." (Fussilat: 9) He set on the (earth), mountains standing firm, high above it, and bestowed blessings on the earth, and measured therein all things to give them nourishment in due proportion, in four days in accordance with (the needs of) those who seek (Sustenance)." (Fussilat: 10) "Then He directed Himself to the heaven and it is a vapor, so He said to it and to the earth: Come both, willingly or unwillingly. They both said: We come willingly. So He ordained them seven heavens in two periods, and revealed in every heaven its affair; and We adorned the lower heaven with brilliant stars and (made it) to guard; that is the decree of the Mighty, the Knowing." (Fussilat: 11 and 12).
Now, let's calculate. God created the firmaments (the sky, the "roof" over the earth] in 2 days + 4 days for the blessings [filling the earth with everything needed for life] + 2 days for creating the earth [the foundation] = 8 days, not 6 days. Now, the question is: Were the heavens and the earth created in 6 days or in 8 days? Where is the problem? Does the problem lie with the miracle of Prophet Muhammad bin Abdullah or with mathematics?
God, the Glorified, has used the word 'qaddara' (measure) for sustenance and the term 'khalaqa' (created) for the heavens and the earth. That is, within these four days, sustenance needed for life on earth was measured, not created. With this explanation the confusion concerning the creation of the heavens and the earth will be done away with, because the problem arises when measurement of sustenance is considered as an act of creation, otherwise basically there would be no problem or contradiction.
To give a precise answer to the above question, it is necessary to first take a look at the verses under question:
إِنَّ رَبَّکُمُ اللَّهُ الَّذی خَلَقَ السَّماواتِ وَ الْأَرْضَ فی سِتَّةِ أَیَّامٍ
"Surely your Lord is Allah, Who created the heavens and the earth in six days." (Al-A'raf: 54)
قُلْ أَ إِنَّکُمْ لَتَکْفُرُونَ بِالَّذی خَلَقَ الْأَرْضَ فی یَوْمَیْنِ.
"Say (O Muhammad, unto the idolaters): Disbelieve ye verily in Him Who created the earth in two Days." (Fussilat: 9)
وَ جَعَلَ فیها رَواسِیَ مِنْ فَوْقِها وَ بارَکَ فیها وَ قَدَّرَ فیها أَقْواتَها فی أَرْبَعَةِ أَیَّامٍ سَواءً لِلسَّائِلین.
"He set on the (earth), mountains standing firm, high above it, and bestowed blessings on the earth, and measure therein all things to give them nourishment in due proportion, in four Days, in accordance with (the needs of) those who seek (Sustenance)." (Fussilat: 10)
فَقَضاهُنَّ سَبْعَ سَماواتٍ فی یَوْمَیْنِ
"So He completed them as seven firmaments in two Days."
"Day" according to Quran
The word day used in the Quranic verses refers to a period of time, not to its lexical and customary meaning. That is because, the word "day" according to the people of the earth is defined as the span of time it takes for the Earth or a celestial body (such as an other planet or a moon) to make a single rotation with respect to a star, measured most accurately from local noon to local noon. The word day used to signify a period of time is very common. The Quran also says, "Such days (of varying fortunes) We give to men by turns." It also says, “What do they wait for then but the like of the days of those who passed away before them?" There are many other examples in which the word “day” has been used to give the meaning of period.
Measurement of Sustenance of the Earth in Four Days:
The question is: How is it that the Quran says in Chapter Fussilat that the creation of the earth has been completed in two days and the mountains, blessings and foods in four days and then the heavens in two days which become totally eight days whereas there are many other verses according to which the heavens and the earth were created in six days or in six periods? 
The commentators of the Quran have adopted different ways in their answers to the above question:
The first way, which is more well-known, is that where the verse says "four days" it refers to the closing four days in the sense that the earth was created in the first two days of these four days and in the second two days, the remaining features of the earth added to it plus other two days in which the heavens were created which in total become six days (six periods).
Similar interpretations exist in Arabic and Farsi languages. For example, when someone says, "It takes ten days to reach Mecca and fifteen to reach Medina" it implies that the distance between Mecca and Medina is five days walk. Obviously, if there were not many verses to emphasize on creation of the heavens and the earth in six days, such an interpretation would not have been accepted. However, since the Quranic verses interpret one another and some verses serve as contexts for other verses, the above interpretation is pretty well acceptable.
Another way which has been adopted by a few commentators is that "four days" do not refer to the beginning of creation; rather they refer to the four seasons of the year which is the source of the creation of the sustenance and nourishment of food stuffs for men and animals.
Third way: The word "measure" has been used to refer to sustenance or food whereas the word "creation" has been used to refer to the creation of the heavens and the earth. That is to say, the measurement (not creation) of the sustenance has been completed within these four days. With this explanation, the confusion concerning the creation of the heavens and the earth will be done away with, because the problem arises when measurement of sustenance is considered as an act of creation, otherwise there would be no problem or contradiction as claimed by some individuals.
Considering the above explanation, "the days which have been mentioned in respect of the creation of the heavens and the earth do not exceed four; two days for the creating the earth and two days for erecting the seven firmaments (skies) after they were vapor. As for the days in which the blessings and sustenance were measured, these two days are the days of their measurement not creation. When God, the Almighty, says that He created the heavens and the earth in six days (not the whole creation and measurement), the truth is that "four days" in the verse qualify only the last sentence in which case there will be no omission or deletion and four refers to the measurement of the sustenance of the earth during the four seasons of the year."
Based on the above, no problem will occur in the miracle of the Prophet (pbuh) nor in mathematics!! The problem arises when we pass judgment without turning to a specialist and expert to seek his advice in such matters.
 - See: Makarem Shirazi, Naser, (Farsi) Translation of the Quran, Darul Quran al-Karim, Qom, second edition, 1994.
 - Aal-e Imran: 140
 - Yunus: 102
 - Tabatabai, Sayyid Muhammad Hussein, Al-Mizan fi Tafsir al-Quran, vol.17, p.362 and 363, Islamic Publications Office of the Society of Teachers of the Islamic Seminary of Qom, Qom, 5th edition, 1417 A.H.
 - Al-Araf:54
 - Naser Makarem Shirazi, Naser, Tafsir Nomouneh, vol.20, p.225.
 - Tabatabai, Sayyid Muhammad Hussein, Al-Mizan fi Tafsir al-Quran, ibid, vol.17, pg.363 and 364.