Google Sheets has a couple of built-in functions — Today and Minus — which can be used to calculate the time difference between a date in the future and today. This article explains how you can use these functions along with our Spreadsheets integration to create a countdown widget for your dashboard. These functions don't update on their own by default so we've written a script for you to use that will ensure your countdown widget is kept up to date.
Setting-up Your Countdown
First, in a Google Sheet, do the following:
- In cell A1, write the label Today
- In cell A2, write the formula
- In cell B1, write the name of the event e.g. Christmas
- In cell B2, write the date of the event, e.g.
(Note: the date needs to be added in the date format mm/dd/yyyy)
- In cell C1, write the label Days Until
- In cell C2, write the formula
=MINUS(B2, A2)(where B2 holds the value of your event and A2 holds the value of today's date)
Next, in your Geckoboard dashboard, do the following:
- Click +Add Widget
- Select the Spreadsheets integration
- Choose the Number widget
- If you haven't already, connect your Google Sheets account to Geckoboard
- Select the Sheet that you saved the above calculation in
- Enter the value of Days Until in the Number selection (in the above example, it is C2)
- Configure the other widget options. Disable the Comparison Visualization and adjust the Title.
- Click Add to dashboard to add your widget to your dashboard
Here are the widget configuration settings:
And this is the resulting Number widget on the dashboard:
Making Your Countdown Update Automatically
Unfortunately, the Google Sheets functions don't automatically update the countdown. The only time the functions update the data is when the Google Sheet is opened. This isn't particularly helpful so we've written a script that updates the data in the Google Sheet every hour, even when the Google Sheet is closed.
Part 1: Write a script
- In your Google Sheet, click on the Tools menu and select the option Script Editor...
- A Google Apps Script window will appear. Click the Blank Project option.
- Replace the default function with the script shown below (Important: Make sure you follow the aforementioned instructions to the letter, otherwise cells in the Sheet might not match the ones in the script and your countdown will not update automatically):
- Save your function and give it a name
Part 2: Set up a trigger
- From inside the Script Editor, click on the Resources menu and select the option Current project's triggers
- In the window that appears, click the link No triggers set up. Click here to add one now.
- This will trigger create the trigger for your function. Use the default options provided.
- Click Save
- You'll be prompted to authorize your app. Click on Continue and then Accept. More information on Google Apps authorization can be found here.
- You can now close the Script Editor
Now that you've written the script and set the trigger running, the countdown on your Google Sheet (i.e. the today() and minus() functions in your Google Sheet) will refresh every hour. This will continue to refresh even when your Google Sheet is closed.
Your Geckoboard widget doesn't require any changes to reflect the addition of this script and trigger; it'll refresh every 10 minutes to check for and fetch new data from your Google Sheet, just as it always has. The difference now is that your Google Sheet will automatically have new data in it!
Note: We've found that occasionally, about a few times a week, a server error will occur on Google's end and the script will fail to run in that particular try. By default, you'll receive an email to notify you that this has happened.
You can simply ignore the errors considering that the script runs every hour each day which totals to 168 times each week, and so a few times a week is nothing to be concerned about.