According to the Department of Consumer Affairs, the 30 clock starts on the day you give notice.
Tenant's notice to end a periodic tenancy
To end a periodic rental agreement (for example, a month-to-month agreement), you must give your landlord proper written notice before you move.
You must give the landlord the same amount of notice as there are days between rent payments.193 This means that if you pay rent monthly, you must give the landlord written notice at least 30 days before you move. If you pay rent every week, you must give the landlord written notice at least seven days before you move.194 This is true even if the landlord has given you a 60-day notice to end the rental agreement and you want to leave sooner (see Landlord's notice to end a periodic tenancy.)195
If your rental agreement specifies a different amount of notice (for example 10 days), you must give the landlord written notice as required by the agreement.196
To avoid later disagreements, date the notice, state the date that you intend to move, and make a copy of the notice for yourself. It's best to deliver the notice to the landlord or property manager in person, or mail it by certified mail with return receipt requested. (You can also serve the notice by one of the methods described under "Proper Service of Notices".)197
You can give the landlord notice any time during the rental period, but you must pay full rent during the period covered by the notice. For example, say you have a month-to-month rental agreement, and pay rent on the first day of each month. You could give notice any time during the month (for example, on the tenth). Then, you could leave 30 days later (on the tenth of the following month, or earlier if you chose to). But you would have to pay rent for the first 10 days of the next month whether you stay for those 10 days or move earlier. (Exception: You would not have to pay rent for the entire 10 days if you left earlier, and the landlord rented the unit to another tenant during the 10 days, and the new tenant paid rent for all or part of the 10 days.)198
The rental agreement or lease must state the name and address of the person or entity to whom you must make rent payments (see When You Rent section).If this address does not accept personal deliveries, you can mail your notice to the owner at the name and address stated in the lease or rental agreement. If you can show proof that you mailed the notice to the stated name and address (for example, a receipt for certified mail), the law assumes that the notice is receivable by the owner on the date of postmark.199
Under Civil Code 1950.5, the landlord is supposed to return your security deposit within 21 days of termination of the rental agreement and provide an itemized breakdown of any deductions, including receipts for any materials or third party services plus the hours and rates for the landlord's employees used. If the landlord retains your security deposit in bad faith, you can recover treble damages.
You should strongly consider documenting the landlord's failure to timely refund your security deposit by sending the landlord a letter pointing out the fact the more than 21 days has passed since you moved out, but you have not received your security deposit or itemized breakdown of any deductions with receipts.
If the landlord fails to comply with Civil Code 1950.5, the landlord is required to refund your entire deposit. Granberry v. Islay Investments, 9 Cal.4th 738, 745 (1995). However, the landlord can still sue you for damages to the property and/or unpaid rent.
Ultimately, the landlord fails to refund your deposit, you may have to sue the landlord in small claims.