(a) Except as provided in subdivision (b), in all leases of lands or tenements, or of any interest therein, from week to week, month to month, or other period less than a month, the landlord may, upon giving notice in writing to the tenant, in the manner prescribed by Section 1162 of the Code of Civil Procedure, change the terms of the lease to take effect, as to tenancies for less than one month, upon the expiration of a period at least as long as the term of the hiring itself, and, as to tenancies from month to month, to take effect at the expiration of not less than 30 days, but if that change takes effect within a rental term, the rent accruing from the first day of the term to the date of that change shall be computed at the rental rate obtained immediately prior to that change; provided, however, that it shall be competent for the parties to provide by an agreement in writing that a notice changing the terms thereof may be given at any time not less than seven days before the expiration of a term, to be effective upon the expiration of the term. The notice, when served upon the tenant, shall in and of itself operate and be effectual to create and establish, as a part of the lease, the terms, rents, and conditions specified in the notice, if the tenant shall continue to hold the premises after the notice takes effect.