Automatically Save Google Docs as PDF with a Timestamp

Automatically saving with a timestamp in the file name creates a dated archive of PDF exports. Each run of the script adds a new file with the date and time in its name, making it easy to track when each version was generated.

Generating a timestamp in Apps Script

Automatically saving with a timestamp uses JavaScript's Date object in the script. Use new Date() to get the current date and time, then format it as a string like YYYY-MM-DD. Append this to the file name before saving: var filename = docTitle + '-' + dateString + '.pdf'.

Formatting the date string

For a sortable date string, use the ISO format YYYY-MM-DD. In Apps Script: var now = new Date(); var dateString = Utilities.formatDate(now, Session.getScriptTimeZone(), 'yyyy-MM-dd'). This produces a string like 2026-03-13 that sorts correctly in alphabetical order.

Adding a time component

For exports that run multiple times per day, add the time: 'yyyy-MM-dd-HH-mm'. This distinguishes exports that happen on the same day at different times. Use this format for on-edit triggers or hourly schedules.

Frequently Asked Questions

Why should I add a timestamp to automatic PDF exports?

Timestamps make it easy to find the version of a document from a specific date. Without timestamps, repeated exports with the same name are hard to distinguish from each other.

Ready to Try It?

Install the free Chrome extension and start converting your Google Docs to PDF in one click.

Install Free Extension