No enhanced penalty may be imposed for any second, third, or subsequent violation, except for an offense pursuant to the provisions of chapter 32-23, unless the defendant was convicted of or plead guilty or nolo contendere to the prior offense previous in time to committing the relevant second, third, or subsequent offense.
SDCL 22-6-5.2