How many days after apologizing do we have to stop committing a sin for God to forgive us?
You seem to have a mistaken idea. When you realize that you are sinning, you should immediately stop. "For the sorrow that is according to the will of God produces a repentance without regret, leading to salvation, but the sorrow of the world produces death. For behold what earnestness this very thing, this godly sorrow, has produced in you: what vindication of yourselves, what indignation, what fear, what longing, what zeal, what avenging of wrong! In everything you demonstrated yourselves to be innocent in the matter" (II Corinthians 7:10-11). Repentance is the idea that you've completely changed your mind about accepting sin, as well as changing your behavior.
A part of that change is that you go to God to apologize for your past mistakes (I John 1:9). If you have not fully decided to stop sinning, then you have not repented and you are not ready to explain to God why you were wrong.