A person convicted of a felony in the district court and held in official confinement while awaiting the outcome of an appeal, writ of error to, or writ of certiorari from, a state or federal appellate court or prior to his release as a result of postconviction proceedings or habeas corpus, shall be given credit for the period spent in confinement against any sentence finally imposed for that offense.
NMS § 31-20-11