
399 N.W.2d 151 (1987)
STATE of Minnesota, Respondent,
v.
Raymond LeRoy RYAN, Appellant.
No. C1-86-1798.
Court of Appeals of Minnesota.
January 13, 1987.
*152 Hubert H. Humphrey, III, State Atty. Gen., St. Paul, Tom Foley, Ramsey County Atty., Darrell C. Hill, Asst. County Atty., St. Paul, for respondent.
C. Paul Jones, State Public Defender, Mollie G. Raskind, Deputy State Public Defender, Minneapolis, for appellant.
Considered and decided by FORSBERG, P.J., and SEDGWICK, HUSPENI, JJ., with oral argument waived.

OPINION
SEDGWICK, Judge.
Appellant contends the sentencing court erred in not granting him jail credit for time spent in custody for violating parole. We reverse.

FACTS
On May 17, 1986, appellant Raymond Ryan was arrested for theft in Ramsey County. He was released on bail May 20, 1986.
Because Ryan was on parole for a prior burglary, he was arrested on July 13, 1986 and jailed in Hennepin County for violating parole. Ryan remained in Hennepin County jail until July 29, 1986, when he pleaded guilty to attempted theft in Ramsey County.
On August 1, 1986, he was sentenced to thirteen months for attempted theft. The court granted Ryan three days jail credit for the period he was jailed on the theft charge before posting bail, and denied credit for the sixteen days he was jailed for violating parole.

ISSUE
Is a criminal defendant entitled to jail credit for time spent in custody solely for violating parole when the offense he is being sentenced on was the basis of the parole violation?

ANALYSIS
The granting of jail credit is not discretionary with the trial court. State v. Doyle, 386 N.W.2d 352, 354 (Minn.Ct.App. 1986).
Minn.R.Crim.P. 27.03, subd. 4(B) provides:
When sentence is imposed the court:
* * * * * *
Shall assure that the record accurately reflects all time spent in custody in connection with the offense or behavioral incident for which sentence is imposed. Such time shall be automatically deducted from the sentence * * *.
(Emphasis added.)
Ryan argues that the time he spent in custody for violating parole was "in connection with" the attempted theft offense for which he was sentenced, and that the trial court erred in not deducting that time from his sentence. He argues that State v. Mattson, 376 N.W.2d 413 (Minn.1985), is controlling and requires reversal. We agree.
In Mattson, the trial court sentenced the defendant for a Minnesota offense and gave him jail credit for time spent in a Wisconsin jail pursuant to a parole hold imposed after Wisconsin authorities learned of the Minnesota charges. Id. at 414. The court of appeals vacated the jail credit. The supreme court reinstated the jail credit, stating:
It is * * * beyond question that the Minnesota offense was the sole reason for defendant's Wisconsin incarceration [for violating parole] * * *.
Id. at 416.
Mattson was followed by this court in Doyle. There, a defendant who was on parole was arrested for burglary and released on bail. He was subsequently jailed for violating parole. This court held that he was entitled to jail credit for the time spent in custody between his imprisonment for violating parole and his pleading guilty to burglary. 386 N.W.2d at 354. We reasoned that under Mattson the time spent in *153 custody for violating parole was "in connection with" the burglary offense. Id.
Here, the State concedes that Ryan was jailed for violating parole solely because of his being arrested for the current offense. Under Mattson and Doyle, time spent in custody for violating parole must be deducted from Ryan's sentence.

DECISION
The sentencing court erred in denying appellant 16 days credit for time spent in jail from July 13 to July 29, 1986.
Reversed.
