How many days will it take for an ruptured eardrum due to a middle ear infection to form back and what are the advice for perforated eardrum?

Weeks. This typically can take weeks. This should be monitored by a primary care physician or ENT to ensure the rupture heals. No submersion of the ear under any type of water until it is healed.
Very fast. Almost all ear drum perforations heal within a few hours to days. Very very few leave a permanent hole. It should be treated with antibiotics.