At the time of sentencing, the court must cause to be recorded on the judgment or commitment the total time in custody to be credited on the sentence under Penal Code sections 2900.5, 2933.1(c), and 2933.2(c). On referral of the defendant to the probation officer for an investigation and report under Penal Code section 1203(b) or 1203(g), or on setting a date for sentencing in the absence of a referral, the court must direct the sheriff", probation officer, or other appropriate person to report to the court and notify the defendant or defense counsel and prosecuting attorney within a reasonable time before the date set for sentencing as to the number of days that defendant has been in custody and for which he or she may be entitled to credit. Any challenges to the report must be heard at the time of sentencing.
Cal. R. Ct. 4.310