
111 Cal.Rptr.2d 815 (2001)
92 Cal.App.4th Supp. 7
NORTH 7th STREET ASSOCIATES, Plaintiff and Respondent,
v.
Guillermo CONSTANTE, Defendant and Appellant.
No. BV 22892.
Appellate Division, Superior Court, Los Angeles County.
July 17, 2001.
*816 A. Christian Abasto and Kenyon Dobberteen, Legal Aid Foundation of Los Angeles, for Defendant and Appellant.
Allen R. King, Los Angeles, for Plaintiff and Respondent.

OPINION AND JUDGMENT
BEVERLY, P.J.
Defendant and appellant Guillermo Constante appeals from the judgment entered against him and in favor of plaintiff and respondent North 7th Street Associates.
This is an action in unlawful detainer. The complaint was based on appellant's failure to vacate the premises following expiration of a 30-day notice to quit. Immediately before trial, respondent made an oral motion to amend the complaint. The amendment alleged that appellant was unlawfully detaining the premises following service of a three-day notice to pay rent or quit, which notice was served approximately six weeks before the 30-day notice was served. Appellant opposed the motion to amend, requesting a continuance to prepare to meet the new allegations should the motion be granted. The trial court *817 granted the motion to amend and denied the request for a continuance. Following a brief recess, trial was held based upon an unlawful detainer following service of the three-day notice to pay rent or quit. Judgment was given for the respondent and this appeal followed.
Appellant contends that the judgment must be reversed because:
1. The amendment to the complaint stated a new and different cause of action not based on the same general set of facts alleged in the original complaint;
2. Respondent inexcusably delayed seeking the amendment;
3. The amendment surprised and prejudiced appellant;
4. The trial court erred in permitting the amendment without a continuance;
5. There was no amendment to conform to proof because the amendment was made before any evidence had been offered; and
6. The trial court's decisions permitting the amendment and denying appellant's request for a continuance violated appellant's right to procedural due process.
"The trial court has broad discretion to grant or deny an amendment to a complaint at trial, and California courts have been extremely liberal in allowing such amendments to conform to proof. [Citations.]." (Glaser v. Meyers (1982) 137 Cal.App.3d 770, 776-777, 187 Cal.Rptr. 242.)
However, the trial court's discretion is not unlimited. "The cases on amending pleadings during trial suggest trial courts should be guided by two general principles: (1) whether facts or legal theories are being changed and (2) whether the opposing party will be prejudiced by the proposed amendment. Frequently, each principle represents a different side of the same coin: If new facts are being alleged, prejudice may easily result because of the inability of the other party to investigate the validity of the factual allegations while engaged in trial or to call rebuttal witnesses. If the same set of facts supports merely a different theory . . . no prejudice can result. As noted by the court in Union Bank v. Wendland [(1976) 54 Cal.App.3d 393, 401, 126 Cal. Rptr. 549]: `[T]he amended pleading must be based upon the same general set of facts as those upon which the cause of action or defense as originally pleaded was grounded.' [Citation.]" (City of Stanton v. Cox (1989) 207 Cal.App.3d 1557, 1563, 255 Cal.Rptr. 682.)
The amendment in the instant case was not based "upon the same general set of facts." The original complaint alleged that the parties were in a landlord-tenant relationship which was terminable by either party upon 30 day's notice and that the landlord had given such notice. The amended complaint alleged that appellant's tenancy was terminated because of his default in payment of rent.
Although the complaint both before and after the amendment required respondent to prove some of the same items, such as a landlord-tenant relationship between the parties, respondent was required to prove different elements of his cause of action as amended, such as the nonpayment of rent.
Additional defenses are available in unlawful detainers based on nonpayment of rent. Defenses available in unlawful detainer are limited to those which, if proven, would maintain the defendant's right to possession. (Green v. Superior Court (1974) 10 Cal.3d 616, 632-633, 111 Cal.Rptr. 704, 517 P.2d 1168.) Payment (or nonpayment) of rent is not an issue in *818 an unlawful detainer based on termination of a periodic tenancy or tenancy at will by a 30-day notice. (Castle Park No. 5 v. Katherine (1979) 154 Cal.Rptr. 498, 91 Cal. App.3d Supp. 6, 12.) In an unlawful detainer based on a three-day notice to pay rent or quit, a defendant may raise the defenses of breach of the warranty of habitabilitycommon law (Green v. Superior Court, supra, 10 Cal.3d at pp. 631-632, 111 Cal.Rptr. 704, 517 P.2d 1168) and statutory (Civ.Code, §§ 1941-1942.5)[1], overstatement of rent in the amount in the notice (Bevill v. Zoura (1994) 27 Cal.App.4th 694, 697, 32 Cal.Rptr.2d 635) and refusal of the landlord to accept tender of rent (Strom v. Union Oil Co. (1948) 88 Cal.App.2d 78, 81, 198 P.2d 347). Appellant did not have the opportunity to investigate the validity of the factual allegations or to call rebuttal witnesses because the trial was held the same day the complaint was amended.[2]
Respondent urges that Code of Civil Procedure section 1173 authorizes the amendment of the complaint and the denial of the continuance request.[3]
Section 1173 states: "When, upon the trial of any proceeding under this chapter, it appears from the evidence that the defendant has been guilty of either a forcible entry or a forcible or unlawful detainer, and other than the offense charged in the complaint, the judge must order that such complaint be forthwith amended to conform to such proofs; such amendment must be made without any imposition of terms. No continuance shall be permitted upon account of such amendment unless the defendant, by affidavit filed, shows to the satisfaction of the court good cause therefor."
Respondent's motion does not come within the scope of the code section. An amendment according to proof is permitted at any time during a trial. (South Bay Building Enterprises, Inc. v. Riviera Lend-Lease, Inc. (1999) 72 Cal.App.4th 1111, 1124, 85 Cal.Rptr.2d 647.) Where the evidence to support the amendment is already before the court, there is usually no prejudice to the opposing party in allowing the amendment. (See Wegner et al., Cal. Practice Guide: Civil Trials and Evidence (The Rutter Group 2000) ¶ 12:394, p. 12-76 (rev.#l, 1999) and cases cited therein.) However, if the evidence is not before the court, that rationale does not apply. (Ibid.)
The motion to amend the pleadings was made before there was any evidence before the court. Appellant would have had the opportunity to challenge the admissibility of evidence establishing the amended allegations had the motion not been granted *819 prior to the introduction of such evidence. At the time the motion was granted it did not "appear from the evidence that the defendant has been guilty of either a forcible entry or forcible or unlawful detainer." (§ 1173.) There was no evidence before the court at all.
The trial courts have discretion in permitting amendments and continuances caused by those amendments. The plain meaning of section 1173 limits the discretion of the court to deny amendment of the complaint or grant a continuance after evidence is admitted which establishes the unlawful detention of the property by the defendant.
The judgment is reversed and the matter is remanded for further proceedings consistent with this opinion. Appellant to recover costs on appeal.
KRIEGLER, J., and P. McKAY, J., concur.
NOTES
[1]  Although appellant did raise a warranty of habitability defense in his answer, the time periods and purpose are different. In defending against a 30-day notice, the sole purpose of the defense is to reduce the amount of daily damages for the period of time after the notice expires. It is not relevant to possession. In defending against a three-day notice to pay rent or quit, the relevant time is the period stated in the notice for which rent was not paid. Proof of the defense will defeat the landlord's right to possession. (2 Moskovitz et al., Cal. Landlord-Tenant Practice (Cont. Ed.Bar 2d ed.1999) § 10:64, pp. 806-807.)
[2]  The case was transferred to Department 81 for trial at 1:30 p.m. It was called for trial on June 1, 2000 at 1:50 p.m. Presumably, during that 20 minute period, the motion to amend was argued and granted, and appellant was given a recess to prepare to meet the amended allegations of the complaint. It is extremely unlikely that appellant would have had time to leave the courthouse to procure additional evidence or that there was time for additional witnesses to be able to reach the courthouse in time to testify.
[3]  Unless otherwise noted, all further statutory references are to the Code of Civil Procedure.
