You can either get the marriage license on the same day or beforehand. you should at least get the marriage license 30 minutes before the ceremony.
you can get the marriage license in other city hall within California.
Santa Clara City Hall: https://www.sccgov.org/sites/rec/Marriage%20Licenses/Pages/Applying-for-a-Marriage-License.aspx