On September 23, 1982, Richard Austin committed robbery in the first degree in Howell County, Missouri. Four days later he committed the offense of kidnapping in Kansas and was there arrested on that charge on September 29. On that same day, a Missouri detainer was lodged against him.
On March 4, 1983, Austin was received by the Kansas Department of Corrections to begin serving a sentence imposed for the kidnapping.
Having been returned to Missouri custody on September 1, 1983, to dispose of the robbery charge, Austin was tried to a jury and convicted. On November 10, 1983, he was sentenced to fifteen years, the court then ordering that he be “allowed credit for all time held on detainer since September 29, 1982.” The number of days to be credited was not specified.
Austin then was returned to Kansas to resume serving his sentence there and was ultimately returned to Missouri on January 3, 1990, to begin serving the fifteen-year robbery sentence here. Having learned af*423ter his return that he had not been given credit for any of the time he had been held “on detainer” in Kansas, as had been ordered by the sentencing court, he first filed an institutional grievance containing the following request: “So would you please look into the matter. My time credit of how much time I have served reflexes [sic] my Custody level and parole date.”
At the fifth and final rung of the grievance ladder, the director of the department of corrections concluded, and so advised Austin, that none of the time served under the Missouri detainer could be credited because a Kansas sentence was being served during its pendency.
Austin then applied for a writ of habeas corpus in the Circuit Court of Randolph County. His petition, against relator herein, superintendent of the Moberly Correctional Center, asserted not one, but two grounds for relief: that “his time was calculated wrong” and that he “was not being allowed all the time credit that was granted him by the Wright County Court.”
A show cause order was issued by the circuit court pursuant to Rule 91.05, the court therein advising that after response had been made, it would “determine whether or not Petitioner is entitled to evidentia-ry hearing and if so will set cause for hearing.”
The superintendent filed a response, stating that petitioner “was not entitled to jail time credit for the period in which he was incarcerated in the Kansas Department of Corrections, even though Missouri had lodged a detainer against [him], because [he] was serving a Kansas sentence.”
Thereafter, the court made the following docket sheet entry:
Court having reviewed the petition, answer thereto and the accompanying filings finds that the facts are not in dispute and the question of credit for jail time is matter of law. The court further finds and [sic] evidentiary hearing is not necessary and will consider the case submitted as of Monday, December 24, 1990. Clerk to notify. [Emphasis added.]
On January 18, 1991, the matter was disposed of by the following docket sheet entry, no formal order having issued:
Matter comes for adjudication. Court finds in favor of Petitioner as to his Motion that he be allowed an additional jail time credit of 337 days as per the order signed on November 10, 1983, by Judge Turner. The jail time of 337 days being those days Petitioner was held on detainer from September 29, 1982 to November 10, 1983 when Judge Turner entered his order in unambiguous language allotting Petitioner those days. Respondent, MO Department of Corrections is hereby ordered to credit Petitioner’s sentence accordingly. Court finds no other relief to be granted. Costs taxed to Respondent, State of Missouri [Emphasis added].
From this decision relator superintendent filed a petition for a writ of certiorari in the court of appeals, contending that the habe-as corpus court acted in excess of its jurisdiction in ordering the time credited. The preliminary writ issued, “that the matter might be reviewed” and that the court “may further cause to be done thereupon what it may appear of right ought to be done.... ” Finding that the habeas corpus court was without jurisdiction to grant the credit, the court of appeals quashed the record and judgment below.
The cause was accepted for transfer here, and we decide the matter as if the writ had been issued by this Court, mindful of the purposes of the writ as aforementioned, searching the record of the circuit court below only for infirmities in jurisdiction or power, and concerned only with questions of law and not of fact.
Before considering the contentions of the parties, it should first be observed that petitioner did not specifically request credit for the 337 days granted him by the habeas corpus court, but only, as aforementioned, for that amount of time which the sentencing court had purported to grant him. The sentencing court had not awarded him a specific number of days, but only, in effect, such time as had been spent on detainer between September 29, 1982, and *424the sentencing proceeding on November 10, 1983. That period encompassed a total of 407 days.
The orders of both the sentencing court and the habeas corpus court may be seen, nonetheless, to be essentially identical. Austin, as earlier stated, had been returned to Missouri custody on September 1, 1983. He was not sentenced, however, until November 10, 1983; thus, for those 70 days, he was not “on” a Missouri detainer but in actual Missouri custody. The difference between 407 days and 70 days is the 337 days ordered credited by the habeas corpus court.
Proceeding first to respondent’s contentions, it is clear that one relates only to procedure: that any claim of error concerning the trial court’s judgment and sentence was waived by failure to raise it at the sentencing proceeding. As to that assertion, the short but dispositive answer is that the issue of jurisdiction is never waived, may be challenged at any time and is the very question upon which the resolution of this case turns.
Respondent’s remaining and principal contention is that because a sentencing court has jurisdiction to impose punishment anywhere within the statutory range, and because no statute or procedural rule prohibits it from extending that jurisdiction to credit the 337 days jail time by reducing the sentence to that extent, it may do so.
The sentencing discretion afforded a judge is of a different nature, however, than that contemplated by respondent. It is for the purpose of suiting the punishment to the crime, rather than adjusting a sentence otherwise appropriate by the number of days perceived by the trial court to be creditable as jail time. Thurston v. State, 791 S.W.2d 893 (Mo.App.1990).
At a time past, discretion did play a part in the crediting of jail time. Under the provisions of § 546.615, RSMo 1959, the predecessor to the present statute, § 558.031, RSMo 1986, credit for time spent between sentencing and delivery to a correctional institution was mandatory. The awarding of that served prior to sentencing, however, was affirmatively reserved to the discretion of the sentencing court.
That discretion was removed, however, by the 1971 amendment to § 546.615, when the crediting of both became mandatory, as they are today under the provisions of § 558.031, whether ordered by the sentencing court or not. It is clear that if the legislature had wanted the court to have discretion in this area, it would have granted it, as it had in the past.
Relator urges, first, that the 337 days were not creditable at all, by the court or the sheriff or the department of corrections, because the confinement was neither “compelled by” Missouri nor “related to” the Missouri charge, citing Harkins v. Lauf, 532 S.W.2d 459 (Mo. banc 1976); and second, that the sentencing court acted outside its jurisdiction in crediting any jail time because no jail time of any kind may be credited except by endorsement thereof on the commitment papers by a sheriff pursuant to subsection 558.031.2, RSMo 1986.
Before relator’s contentions are further considered, additional analysis is appropriate. As hereinbefore stated, the prisoner’s petition requested that the habeas corpus court do two things: Order him to be credited with the jail time granted by the sentencing court, and to make inquiry into whether or not relator had calculated his jail time correctly.
In determining whether respondent exceeded his jurisdiction, the overriding question, however, is whether the sentencing court had jurisdiction to award the jail time in question. If it did not, neither did the habeas corpus court have jurisdiction to order it credited.
It is to be noted that every provision of § 558.031 appears clearly to contemplate that the department, and not the sentencing court, is to be the actor in the crediting of jail time. The word “court” never appears in this section, although it consistently does wherever in the remainder of chapter 558 it is the court that is to act. The pertinent statute, with those matters pecu*425liarly within the scope of the knowledge and function of the executive branch italicized, reads:
558.031.1 A person convicted of a crime in this state shall receive as credit toward service of a sentence of imprisonment all time spent by him in prison or jail both because awaiting trial for such crime and pending transfer after conviction to the department of corrections and human resources or the place of confinement to which he was sentenced. Time required by law to be credited upon some other sentence shall be applied to that sentence alone, except that
(1) Time spent in jail or prison awaiting trial for an offense because of a detainer for such offense shall be credited toward service of a sentence of imprisonment for that offense even though the person was confined awaiting trial for some unrelated bailable offense; and
(2) Credit for jail time shall be applied to each sentence if they are concurrent. 558.031.2 The officer required by law to deliver a convicted person to the department of corrections and human resources shall endorse upon the commitment papers the period of time to be credited as provided in subsection 1 of this section.
558.031.3 If a sentence of imprisonment is vacated and a new sentence is imposed on the defendant for the same offense, the new sentence is calculated as if it had commenced at the time the vacates sentence was imposed, and all time served under the vacated sentence shall be credited against the new sentence. 558.031.4 If a person serving a sentence of imprisonment escapes from custody, the escape interrupts the sentence. The interruption continues until the person is returned to the institution in which the sentence was being served, or in the case of one committed to the custody of the department of corrections and human resources, to any institution administered by the department.
558.031.5 If a person released from imprisonment or parole or serving a conditional release term violates any of the conditions of his parole or release, he may be treated as a parole violator under the provisions of section 549.265, RSMo. If the board of probation and parole revokes the parole or conditional release, the paroled person shall serve the remainder of his prison term and all the conditional release term as an additional prison term, unless he is sooner released on parole under section 549.261, RSMo.
These prescriptions cannot reasonably be interpreted as being directed to courts; nor is the information necessary to carry them out convenient (if, indeed, as a practical matter, available at all) to the sentencing court.
The very sentencing proceeding in this case is illustrative of the problem with both ordinary jail time spent between arrest and delivery to a correctional institution, and that served on detainer in a foreign jurisdiction. Assuming the necessity of at least a minimal factual basis for the proper calculating and crediting of jail time served on detainer in a foreign jurisdiction, it would have been necessary for evidence in the possession of the Missouri or Kansas corrections departments, or both, to have been presented. The testimony of the defendant himself would have been relevant, and any finding would have been reviewable by direct appeal, rather than by post-conviction motion or habeas corpus.
Further, while the legal file indicates that Austin was credited by sheriffs endorsement with the 53 days he had spent in Wright County, where he was sentenced, an additional 22 days served in Howell County, where the crime was committed, were not endorsed by the sheriff. The department of corrections, however, was able to and did credit them long after the sentencing court lost jurisdiction of the case.
It is thus clear, and this Court holds, that this statutory scheme contemplates an administrative and not a judicial determination of the jail time to be credited, with no sharing of jurisdiction between the two branches of government. Thus, *426since the sentencing court had not the jurisdiction to award the 337 days in question, neither did the habeas corpus court if its decision was based solely upon that of the sentencing court.
This leads to the final consideration and disposition of relator’s contentions. It is to be noted that, with but one exception, all of the eases cited on the issue of the crediting of jail time, including Harkins, supra, relied on by relator, were decided pursuant to § 546.615, which was repealed effective January 1, 1979, rather than § 558.081, which applies to this case. The one exception is Seevers v. State, 766 S.W.2d 780 (Mo.App.1979). In that case, however, the time served in Texas was not creditable because it was not shown to come within the present statute, rather than because detainer time in a foreign jurisdiction was categorically not creditable.
Contrary to the contention of relator, Harkins may not be said to have conclusively precluded then what the statute now specifically permits: credit for time served in another state “because of” (“compelled by,” in the language of Harkins) a Missouri detainer. Whether the foreign offense is “related” to the Missouri charge is subsumed by whether the confinement is because of the Missouri detainer. If so, the time is creditable even if served awaiting trial on an unrelated bailable offense. § 558.031.1(1), RSMo 1986.
Neither does credit for detainer time require endorsement by a sheriff. The only category of time creditable under the old statute and the new was and is that peculiarly within his knowledge: time served in his jail. Detainer time is now statutorily creditable, but upon facts almost certain to be, as in this case, exclusively within the peculiar knowledge of the department of corrections.
While the habeas corpus court had no jurisdiction to review the action of the sentencing court, it had not only the jurisdiction but the duty, under the pleadings, to make a factual inquiry into the propriety of the calculation by relator that no jail time was to be credited. That the jurisdiction of that court may be further and finally exercised, this cause must be returned there; that it may be properly exercised, further analysis is appropriate.
Obviously, two different categories of time are contemplated by the statute. One is governed by § 558.031.1 and consists exclusively of jail time served awaiting trial (and, obviously, sentencing) as well as that between sentencing and delivery to a correctional institution. The other, provided for by § 558.031.1(1), is jail or prison time spent, in the words of the statute, here emphasized, “because of’ a detainer, “even though ... confined awaiting trial for some unrelated bailable offense.” In the instant case, the only kind of time in issue, of course, is the latter.
Crucial are the facts upon which the calculation of credit must be based. As stated hereinbefore, the prisoner was arrested in Kansas for the Kansas offense of kidnapping on September 29, 1982, but not delivered to the Kansas Department of Corrections until March 4, 1983, some 156 days later. This indicates that, during that period, the confinement, or at least part of it, may well have been because o/the Missouri detainer and thus creditable (even though also served while awaiting trial for the Kansas offense, presumably bailable, of kidnapping).
On the other hand, it may also be that, while not serving time under a Kansas sentence and judgment during that period, he was confined in such other unbailable status as that of a parole violator, for which credit may not properly be given. These are but examples of matters that remain to be considered and resolved by the habeas corpus court.
To the extent the record and judgment of the habeas corpus court relate to the crediting of the 337 days jail time in question, the same are quashed. To the extent the writ of certiorari commands respondent to desist from further proceedings in the matter, the writ is quashed, and the cause remanded to the Circuit Court of Randolph County for the exercise of its jurisdiction in determining whether relator properly cal*427culated the jail time and, if not, to assure that he does.
ROBERTSON, C.J., and COVINGTON, BENTON, and THOMAS, JJ., and RENDLEN and BLACKMAR, Senior Judges, concur.
HOLSTEIN, J., not sitting.