When was it that the verses of the Qur'an, revealed, as they were, at different times, came to be compiled as a complete whole?

The compilation of the Qur'an took place along with its revelation. The fact of the matter is that it was the Lord Creator Himself, Who had revealed the Holy Qur'an, who had taken up the responsibility of its compilation also. Allah says: 'It is for Us to collect it and to recite it. But when We have recited it, follow thou its recital (as promulgated)' (75:17,18)

Gabriel (عليه السلام), who used to bring the revelation to Muhammad (S.A.W), also used to  inform him as to the number and position as well as the particular chapter in which each verse was to be located. The followers of the Prophet who used to transcribe the Qur'an were, themselves, referred to as Kuttabul Wahy (or the writers of the revelation). The major figures in this group were the Ansars Ubayy bin Ka'ab, Muaad bin Jabal, Zaid bin Thabit and Abu Zaid (may the pleasure of Allah be upon them all). They used to write down the Qur'an mainly on sheets of leather. Whenever the Prophet received a revelation, he used to call forth these scribes. He would then instruct them in the order which Gabriel had commanded him. In other words, they would be told as to the chapter and the position, therein, of each of these verses. They would then write it down accordingly. Thus it was that the compilation of the Qur'an also took place along with its revelation in the time of the Prophet itself.

Look at some of the hadith which are related to the subject: Usman (r) said: 'The messenger of God used to receive various chapters at the same time. On such occasions he would call the scribes and order them to include these verses in a particular chapter which dealt with a particular subject.' (Tirmudhi)

'Gibriel (a) used to recite to the Prophet the entire Qur'an once every year. As for the year of his death he was recited the Qur'an twice.' (Bukhari).

Whenever a verse was revealed, therefore, the divine instruction as to its number and chapter in which it is to be positioned was also sent alongside. The Prophet then instructed the scribes to write it down accordingly. Further, Gabriel (a) himself, used to recite the entire revelation, up to  the portion that has been revealed, to the Prophet to which the Prophet, in his turn, listened  attentively. Then the Prophet would recite it to Gabriel. Thus the Prophet managed to be completely loyal to the divine instructions with regard to the order in which the Qur'an was to be compiled. We witness here the honest fulfillment of the divine statement that 'It is for Us to collect it and to recite it.' (75:17)