
60 Cal.Rptr.3d 182 (2007)
151 Cal.App.4th 861
The PEOPLE, Plaintiff and Appellant,
v.
Juan Pablo MENDEZ, Defendant and Respondent.
No. A114166.
Court of Appeal of California, First District, Division One.
May 31, 2007.
*183 Bill Lockyer and Edmund G. Brown, Jr., Attorneys General of the State of California, Mary Jo Graves, Chief Assistant Attorney General, Gerald A. Engler, Senior Assistant Attorney General, Seth K. Schalit, Supervising Deputy Attorney General, Moe Jamil, Deputy Attorney General for Plaintiff and Appellant.
Gordon S. Brownell, St. Helena, for Defendant and Respondent.
STEIN, J.
In 1992, defendant Juan Pablo Mendez was found not guilty by reason of insanity on charges unrelated to this appeal, and committed to Napa State Hospital (the hospital) pursuant to Penal Code section 1026.[1] The period of that commitment (the civil insanity commitment) was due to end on November 12, 2005. On December 10, 2003, a felony complaint was filed, charging defendant with assaulting another hospital patient with a deadly weapon by means of force likely to produce great bodily injury. (§ 245, subd. (a)(1).) As a result of that charge, defendant was transferred to county jail on January 7, 2004. On February 3, 2004, the court found defendant mentally incompetent to stand trial. On February 24, 2004, it ordered defendant committed to the hospital for a period not to exceed three years, or until his mental competency had been restored. (§ 1370, subd. (c)(1).)
Defendant was returned to the hospital on April 6, 2004, where he remained until September 21, 2005. At that time he was returned to the county jail. On October 3, 2005, the court found him to be mentally competent to stand trial and criminal proceedings were reinstated. Defendant ultimately pleaded guilty and was sentenced to four years in state prison. The court awarded defendant 279 days' actual credit and 138 days' conduct credit for time served in the county jail. Later, over the People's objection, the court awarded defendant additional credits of 534 days for time spent at the hospital between April 6, 2004, and September 21, 2005.[2]
The People appeal, contending the court erred in awarding the additional 534 days' credit to defendant. We agree.

DISCUSSION
Section 2900.5 requires an award to a defendant of credit against his or her sentence for time spent in presentence custody. (§ 2900.5, subd. (a).[3]) The legislative *184 purpose of the statute is "to eliminate the unequal treatment suffered by indigent defendants who, because of their inability to post bail, served a longer overall confinement than their wealthier counterparts. [Citations.]" (In re Rojas (1979) 23 Cal.3d 152, 156, 151 Cal.Rptr. 649, 588 P.2d 789 (Rojas).) Section 2900.5 applies to persons, such as defendant, who were confined in a state hospital as mentally incompetent to stand trial, so that they are entitled to credit for the time of that confinement against any sentence imposed upon a conviction after competency has been restored. (People v. Callahan (2006) 144 Cal.App.4th 678, 684, 50 Cal. Rptr.3d 677 (Callahan); People v. Cowsar (1974) 40 Cal.App.3d 578, 579, 115 Cal. Rptr. 160.)
There is, however, a limitation. Section 2900.5, subdivision (b) provides, as relevant here, "For purposes of this section, credit shall be given only where the custody to be credited is attributable to proceedings related to the same conduct for which the defendant has been convicted." A defendant is entitled to credit for presentence custody only if he shows the conduct that led to his conviction "was the sole reason for his loss of liberty during the presentence period." (People v. Bruner (1995) 9 Cal.4th 1178, 1191, 40 Cal. Rptr.2d 534, 892 P.2d 1277; Rojas, supra, 23 Cal.3d at p. 156, 151 Cal.Rptr. 649, 588 P.2d 789; Callahan, supra, 144 Cal. App.4th at p. 685, 50 Cal.Rptr.3d 677.) "Section 2900.5 does not authorize credit where the pending proceeding has no effect whatever upon a defendant's liberty." (Rojas, at p. 156, 151 Cal.Rptr. 649, 588 P.2d 789.) This rule applies not only when the defendant's loss of liberty resulted from a criminal sentence, but also when the loss of liberty, as here, resulted from a civil insanity commitment. As we explained in Callahan, "The question is not the type of liberty deprivation, but the fact of the liberty deprivation itself. Logically, the key question is whether defendant would have been free if he had sufficient funds to make bail on the new criminal charge. If he would have remained in custody in any case, regardless of the characterization of that custody as criminal or civil, he is simply not entitled to actual custody credit." (Callahan, supra, at p. 686, 50 Cal.Rptr.3d 677, italics in the original.) Here, irrespective of any confinement related to the 2003 felony complaint, defendant would have been confined to the hospital as a result of a civil insanity commitment on unrelated charges until November 12, 2005. His presentence confinement on the current charges therefore was not the sole reason for his loss of liberty during the presentence period, and section 2900.5, therefore, does not authorize an award of credits for that period.
Defendant contends that the rule stated in Callahan, supra, 144 Cal.App.4th 678, 50 Cal.Rptr.3d 677 does not apply here. In Callahan, the defendant was confined in a state hospital on a 1997 insanity commitment when he was charged with battery upon a hospital guard. '(I'd. at p. 681, 50 Cal.Rptr.3d 677.) Like defendant here, the defendant in Callahan was found to be incompetent to stand trial on the new charge, and was ordered committed to the hospital until his competency was restored. Unlike defendant here, the Callahan defendant's competency never was restored to the extent he was competent to stand trial on the new charge. (Id. at pp. 682-683, 50 Cal.Rptr.3d 677.) In defendant's opinion, this distinction is significant because of section 1375.5. Section 1375.5 provides, "Time spent by a defendant in a hospital or other facility as a result of a commitment therein as a mentally incompetent pursuant to this chapter shall be credited on the term of any imprisonment, if any, for which the defendant is sentenced *185 in the criminal case...." Defendant claims section 1375.5 requires an award of credits to any person falling within its provisions, even if none would be available under section 2900.5. As defendant points out, the Callahan defendant was not affected by section 1375.5 because he was never sentenced in a criminal case. Defendant, however, was sentenced and therefore falls within the provisions of section 1375.5. According to defendant, it follows that he is entitled to an award of credits by reason of section 1375.5 even though none would be available to him by reason of section 2900.5.
Defendant's position makes little logical sense as there is no reason to award credits to a defendant for time spent in a facility when the defendant would have spent time in the facility irrespective of confinement on a current charge. Section 1375.5 does no more than provide that credits will be given for time spent in a hospital as a result of a commitment therein as mentally incompetent. Defendant would have been in the hospital whether or not he was committed there as a mentally incompetent, and therefore was not in the hospital as a result of that commitment. Section 1375.5 provides no basis for crediting him with that period of confinement even though the days of confinement were the same.

DISPOSITION
The order awarding defendant 534 days' credit for time spent Napa State Hospital is reversed.
We concur: MARCHIANO, P.J., and SWAGER, J.
NOTES
[1]  All further statutory references are to the Penal Code.
[2]  The People have not sought reversal of the award of credits for time served in the county jail.
[3]  Section 2900.5, subdivision (a) provides in relevant part, "In all felony and misdemeanor convictions, either by plea or by verdict, when the defendant has been in custody, including, but not limited to, any time spent in a ... hospital ..., all days of custody of the defendant ... shall be credited upon his or her term of imprisonment...."
