Add a Countdown Clock to Project Timelines in Docs

Max Brawer
2 min readMay 23, 2023

--

Update: if you love Apps Script, you will love my new page www.sheetswizard.com/ where I am launching more products and content made to help you become the best operator in your entire organization!

In taking on more independent projects this year, one client put me in the Project Manager seat to help with an office move-out and digital transformation (going “Virtual” at last). This gave me an opportunity to use all the new Notion-style features added to Google Docs for time and project tracking:

At last! Tables and Dropdowns

While users of Docs can do so much more to manage a project (not to mention the ability to view a Gantt Chart / Timeline in Sheets), the very first thing I set out to do, I could not — use the new time chips to count down the days until moving day dynamically.

These are cool, but not solving my need

Good news is, with Apps Script all things are possible in just a few lines of code (vigilante product management as I call it!). After a quick visit to ChatGPT for a date-diff function, all one needs to do is go to Extensions > Apps Script and plug in some code:

function diffDays() {
const oneDay = 24 * 60 * 60 * 1000;
const firstDate = new Date();
const secondDate = new Date("06/30/2023"); // move out
const diffDays = Math.round(Math.abs((firstDate - secondDate) / oneDay));
return diffDays;
}

function update() {
const days = diffDays();
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
const p = body.getParagraphs()[0];
p.editAsText().setText("Move Out: June 30th (" +days+ " days from now)");
}

…and set a time based trigger to update daily. The end result in this quick snippet looks like:

Automatically generated each day

This solution isn’t very scalable because it just makes a header paragraph to get the message out. I am debating making it into a product that can be placed dynamically — if you would find that interesting, please send a message here in the comments, on LinkedIn, or inquiries@maxbrawer.com.

Max is the founder of sheetswizard.com, which is full of other apps and how-to’s like this one. You may also like Calendar Timeline View or TIMEDIF if you enjoy these time-based tools!

--

--

Max Brawer
Max Brawer

Written by Max Brawer

People Tech & Analytics leader @ Atlassian, formerly Twitch, BuzzFeed, Google, Nielsen | Try his apps @ sheetswizard.com

No responses yet