
94 Ill. App.3d 131 (1981)
418 N.E.2d 200
ROLAND JACKSON, Petitioner-Appellant,
v.
J.W. FAIRMAN, Warden, et al., Respondents-Appellees.
No. 16532.
Illinois Appellate Court  Fourth District.
Opinion filed March 13, 1981.
Rehearing denied April 10, 1981.
*132 Daniel D. Yuhas and Janet Sinder, both of State Appellate Defender's Office, of Springfield, for appellant.
Tyrone C. Fahner, Attorney General, of Chicago (Melbourne A. Noel, Jr., Assistant Attorney General, and Jay D. Stein, law student of counsel), for appellees.
Reversed and remanded.
Mr. JUSTICE CRAVEN delivered the opinion of the court:
Petitioner appeals the dismissal of his writ of habeas corpus by the trial court. We reverse.
In 1977, petitioner was convicted of robbery and sentenced to 3 years' imprisonment. He began serving that term in October of 1977 and was released in April of 1979. As of his release date, he was required to serve a 2-year term of mandatory supervised release.
Petitioner was rearrested for theft on May 23, 1979, and has been incarcerated since that date. He was subsequently convicted of theft and on February 5, 1980, he was sentenced to 2 years' imprisonment for the theft. On April 15, 1980, petitioner's mandatory supervised release for the 1977 robber conviction was revoked.
Petitioner received credit for the time incarcerated between May 23, 1979, the date of his subsequent arrest, to February 5, 1980, the date of sentencing, against his theft conviction but not the robbery supervised release. No credit for any time incarcerated since May 23, 1979, was applied against his mandatory supervised release revocation sentence.
Petitioner filed a writ of habeas corpus asking that the trial court order the Department of Corrections to recompute his out date and apply credit for time incarcerated for the revocation of his mandatory supervised release sentence.
On appeal, petitioner argues that he is entitled to have the time he *133 was incarcerated between February 5, 1980, the date he was sentenced for the theft conviction, and April 15, 1980, the date his mandatory supervised release was revoked, credited against the revocation sentence, under the authority of section 3-3-9(a)(3)(ii) of the Unified Code of Corrections (Ill. Rev. Stat. 1979, ch. 38, par. 1003-3-9(a)(3)(ii)). We conclude that petitioner is entitled to such relief.
The aforementioned statute provides that if the prison review board revokes an individual's mandatory supervised release and reconfines him for a violation of that release, "the person shall be given credit against the term of reimprisonment or reconfinement for time spent in custody since he was paroled or released which has not been credited against another sentence or period of confinement." Respondents argue that since the time defendant had spent in incarceration between February 5, 1980, and April 15, 1980, operates to help discharge his theft sentence, that time was thereby "credited against" the theft sentence within the meaning of the statute and could not be credited against the revocation sentence. We disagree.
 1 We interpret the statutory phrase "credit against" to mean the crediting, whether by operation of law or by court order, which occurs at the time a sentence is imposed on the subsequent conviction, and not at the time an individual's mandatory supervised release is revoked. Thus, the time petitioner spent in jail between February 5, 1980, and April 15, 1980, although it operated to discharge his theft sentence, should have been credited against his sentence upon reimprisonment following revocation of his mandatory supervised release.
Adoption of respondents' argument, we conclude, would lead to anomalous results. Under respondents' theory, either through inadvertence or design, the revocation proceeding could be delayed until petitioner had all but served out his sentence for the subsequent conviction. If time served on that conviction cannot be applied to the revocation term, the petitioner would be forced to serve what amounts to consecutive sentences, a result which is clearly not in accord with the statutory purposes of the Unified Code of Corrections.
 2 We also reject respondents' argument that the trial court lacked jurisdiction because the proper remedy of petitioner was a writ of mandamus rather than a writ of habeas corpus. Section 37 of the Habeas Corpus Act (Ill. Rev. Stat. 1979, ch. 65, par. 36.1) provides that if a court determines that plaintiff has pleaded or established facts which entitle him to relief but he has sought the wrong remedy, the trial court shall permit the pleadings to be amended and shall grant relief to which plaintiff is entitled on the amended pleadings or upon the evidence. Petitioner, having established his right to relief, should not be precluded from that relief because he chose the wrong remedy in his pro se petition.
*134 For the foregoing reasons, the judgment of the circuit court is reversed and the cause is remanded with instructions to credit petitioner's mandatory supervised release term with credit for time spent while incarcerated between February 5, 1980, and April 15, 1980.
Reversed and remanded with directions.
WEBBER and GREEN, JJ., concur.
