The Quran has not ordained as to how long mothers MUST suckle the child. The individual circumstances would be the deciding factor in this respect. However, the Quran has said that it takes two and a half years for a mother to bear the burden of the foetus in her womb followed by the suckling of the child.
And We have enjoined on man doing of good to his parents; with trouble did his mother bear him and with trouble did she bring him forth; and the bearing (the burden) of him and the weaning of him was thirty months; ...
At another place the suckling period is described as two years.
And We have enjoined man in respect of his parents-- his mother bears him with weakness (and hardships) upon weakness (and hardship) and his weaning takes two years-- saying: Be grateful to Me and to both your parents; to Me is the eventual coming.
In certain cases, fixing of the period of suckling becomes a legal necessity. For example, if a man divorces his wife and she is still breastfeeding the baby, then still according to the Quran rearing the baby is the father's responsibility, and if the father dies then it is the responsibility of his inheritors.
And the mothers should suckle their children for two whole years for him who desires to make complete the time of suckling; and their maintenance and their clothing must be-- borne by the father according to usage; no soul shall have imposed upon it a duty but to the extent of its capacity; neither shall a mother be made to suffer harm on account of her child, nor a father on account of his child, and a similar duty (devolves) on the (father's) heir, but if both desire weaning by mutual consent and counsel, there is no blame on them, and if you wish to engage a wet-nurse for your children, there is no blame on you so long as you pay what you promised for according to usage; and be careful of (your duty to) Allah and know that Allah sees what you do.
Let the women live (in 'iddat) in the same style as ye live, according to your means: Annoy them not, so as to restrict them. And if they carry (life in their wombs), then spend (your substance) on them until they deliver their burden: and if they suckle your (offspring), give them their recompense: and take mutual counsel together, according to what is just and reasonable. And if ye find yourselves in difficulties, let another woman suckle (the child) on the (father's) behalf.
The legal importance of the suckling period can be understood from an example. If a man dies and his widow keeps on breastfeeding the baby, then she can claim compensation through the court from his successors. However, this will be till the child is two years old, and not beyond.