As soon as you believe!  Baptism is for anyone who has chosen to become a follower of Jesus.  Baptism will not give someone eternal life. That comes through faith in Jesus.  Baptism is a way of publicly identifying with Jesus.  If we waited until we were perfect before being baptized, we would never be baptized!