Timestamp PDF Filenames When Saving to Drive

A timestamp in the filename makes every export unique, prevents overwrites, and lets you sort files chronologically. This is the simplest way to build a PDF version history without managing folder structures.

Formatting the timestamp

Use Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd_HH-mm-ss') to generate a sortable timestamp string. The format YYYY-MM-DD sorts chronologically when files are listed alphabetically, which is a key advantage over formats like MM/DD/YYYY.

Combining name and timestamp

A good filename pattern is: docName + '_' + timestamp + '.pdf'. This keeps the document name first for easy scanning and appends the timestamp for uniqueness. Avoid spaces in the filename; use underscores or hyphens instead.

Cleaning up old timestamped files

Timestamped files accumulate over time. Set up a separate cleanup function that scans the output folder and trashes files older than a certain number of days. Run it on a monthly trigger to keep the folder from growing indefinitely.

Frequently Asked Questions

Which timestamp format is easiest to sort in Google Drive?

ISO 8601 format: YYYY-MM-DD or YYYY-MM-DD_HH-MM-SS. Files named this way sort correctly when sorted alphabetically in Drive, with the oldest files first and the newest last.

Ready to Try It?

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

Install Free Extension