the Fatwa Department Research Committee - chaired by Sheikh `Abd al-Wahhâb al-Turayrî
Scholars disagree over this issue. The opinion of most scholars is that it was legislated in the second year after the emigration to Madinah (in other words, 2 AH). Other scholars have placed the date even later, while still other scholars, among them Ibn Khuzaymah, have said that it was legislated before the Prophet (peace be upon him) departed from Mecca.
It can safely be said that the obligation to give charity was imposed in Mecca, in at least a very general sense. Evidence that charitable spending was already obligatory upon the Muslims while they were still in Mecca can be taken from the verse: "And woe to those who join gods with Allah, those who do not pay Zakâh and who even deny the Hereafter.” [Sûrah Fussilat: 6-7]
This verse was revealed in Mecca, and is evidence that Zakâh was already something obligatory and not merely preferable. Therefore, the obligation of paying "Zakâh" was already in place during the Meccan period. However, there is no evidence that there was a fixed rate for it or that its rulings had been set forth in any detail. Therefore, it was probably simply an obligation for charitable spending in a very general sense.
Later on, in Madinah, the various legislations regarding Zakâh were revealed. These include the types of wealth which are subject to Zakâh, the percentage that must be levied on each types of wealth, when and how often Zakâh is due, and those who are entitled to receive it.
Before that, Muslims were simply asked to help the needy, feed the poor, ransom prisoners of war, and assist anyone in trouble.
The general duty of charitable spending existed in Meccan society even before the advent of Islam. Therefore, when Islam commanded Zakâh in Mecca, there would already have been a general understanding in place of what this entails, allowing the early Muslim community to put the general principle of Zakâh into practice long before the detailed rulings were revealed.
For example, it is mentioned in Sahîh al-Bukhârî (4) and Sahîh Muslim (160), that Khadijâh, the wife of the Prophet (peace be upon him), reassured him when he received his first revelation: "By Allah, He will never let you down, for you uphold ties of kinship , help people in difficulty, give to the needy, honor the guest, and give assistance in calamities."
And Allah knows best.
Source: Islam Today