At any time after the commencement of a prosecution for an offense and prior to the sentencing of the defendant, the defendant or the prosecuting attorney may file a motion for a hearing to determine the mental competency of the defendant. The court shall grant the motion, or shall order such a hearing on its own motion, if there is reasonable cause to believe that the defendant may presently be suffering from a mental disease or developmental disability, or other conditions set forth in § 23A-10A-1, rendering the defendant mentally incompetent to the extent that the defendant is unable to understand the nature and consequences of the proceeding against the defendant or to assist properly in the defendant's defense. Prior to the date of hearing, the court may order that a psychiatric or psychological examination of the defendant be conducted, and that a psychiatric or psychological report be filed with the court, pursuant to the provisions of §§ 23A-46-1 and 23A-46-2. The examination shall be completed within twenty-one days of the court order, unless for good cause the court grants a continuance. The hearing shall be conducted pursuant to the provisions of § 23A-46-3.
SDCL 23A-10A-3