Whenever it is necessary to allege a prior conviction of the accused in an indictment, it is sufficient to allege that the accused was at a certain stated time, in a certain stated court, convicted of a certain stated offense, giving the name of the offense, if it have one, or stating the substantial elements thereof.