Time spent in custody because of orders issued pursuant to sections 1026, 1032, and 1040 shall be credited against any sentence imposed on the defendant in the pending criminal case or in any other case arising from the same transaction.
MCL 330.2042