It can take several months to a few years for a cavity to form depending on various factors, including oral hygiene and diet.