# How to build a countdown timer for 60 seconds

**URL:** <https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979>\
**Category:** Need help\
**Created:** [March 28, 2025, 1:11pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979 "2025-03-28T13:11:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 28, 2025, 1:11pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/1 "2025-03-28T13:11:51Z")

</div>

I have built a countdown timer for 60 seconds using “Do every 1 second” and Custom State. However, whenever I move away from the page it stops ticking down. When I come back to the page it starts ticking down from where I had left. How do I resolve this issue.

---

<div class="post-metadata">

**Author:** ![hpelenga](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/hpelenga/32/243344_2.png) [@hpelenga](https://forum.bubble.io/u/hpelenga)\
**Post date:** [March 28, 2025, 7:31pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/2 "2025-03-28T19:31:28Z")

</div>

Hey!

The issue is that the “Do every 1 second” actions stop when you leave the page. A simple fix would be to store the remaining time in a database or a persistent Custom State. You update this value every second, and when you come back to the page, you just grab that value and pick up the countdown from where you left off.

That should fix it!

---

<div class="post-metadata">

**Author:** ![hi.luisacosta](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/hi.luisacosta/32/249869_2.png) [@hi.luisacosta](https://forum.bubble.io/u/hi.luisacosta)\
**Post date:** [March 28, 2025, 8:02pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/3 "2025-03-28T20:02:49Z")

</div>

The simplest way to do this is use the plugin: Current Date/Time by Mintflow

This gives you an active time because in bubble when you use “Current Date/Time” it gives you the time at page load.

So using this plugin you can set the Start Time and then use Start\_time - Date-Plugin’s current time: formatted as seconds to get the time you need

---

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 29, 2025, 7:07am UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/4 "2025-03-29T07:07:19Z")

</div>

Hey. Thanks for your reply. Can you elaborate on persistent Custom State?

---

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 29, 2025, 7:10am UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/5 "2025-03-29T07:10:10Z")

</div>

Hey. Thanks for your reply. So my page has a group with one question to be answered within 60 seconds. And I need to disable submit button after 60 seconds and load the next question from DB. Will I be able to do this with plug in?

---

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 29, 2025, 7:37am UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/6 "2025-03-29T07:37:54Z")

</div>

Hey. Thanks for your reply. Just to elaborate, my page has a group which displays question to be answered within 60 seconds. I disable submit button after 60 seconds and on clicking Next another question is retrieved from DB.

So what I observed is when I go to some other website in some other tab, my timer stopped ticking though the question page was still open.

Will persistent Custom State resolve this? Is there a YouTube video or any article on it?

---

<div class="post-metadata">

**Author:** ![ihsanzainal84](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ihsanzainal84/32/245932_2.png) [@ihsanzainal84](https://forum.bubble.io/u/ihsanzainal84)\
**Post date:** [March 29, 2025, 1:32pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/7 "2025-03-29T13:32:00Z")

</div>

If the question is a database record just save a start time value and then do a conditional check against that value for if 60 seconds have passed.

---

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 29, 2025, 5:04pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/8 "2025-03-29T17:04:44Z")

</div>

But that is the problem. How do I check whether 60 seconds have passed. The custom state based logic doesn’t work when I am browsing some other website.

---

<div class="post-metadata">

**Author:** ![adamhholmes](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/adamhholmes/32/100510_2.png) [@adamhholmes](https://forum.bubble.io/u/adamhholmes)\
**Post date:** [March 29, 2025, 5:08pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/9 "2025-03-29T17:08:30Z")

</div>

The start time needs to be stored int eh database (or some other persistent storage)

---

<div class="post-metadata">

**Author:** ![hi.luisacosta](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/hi.luisacosta/32/249869_2.png) [@hi.luisacosta](https://forum.bubble.io/u/hi.luisacosta)\
**Post date:** [March 29, 2025, 8:05pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/10 "2025-03-29T20:05:26Z")

</div>

Yes you can do it with the plugin. This plugin **will allow** you to see the time passed even if you leave the window.

Another method: You may also “lock” a question via scheduled workflow that happens 60 seconds after someone begins a question. Then the client side is checking the Is\_Locked? field instead of relying on the front end time calculation.

First try the plugin and then move into using the DB.

---

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 30, 2025, 7:17am UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/11 "2025-03-30T07:17:48Z")

</div>

Okay. I will try this.

---

<div class="post-metadata">

**Author:** ![ihsanzainal84](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/ihsanzainal84/32/245932_2.png) [@ihsanzainal84](https://forum.bubble.io/u/ihsanzainal84)\
**Post date:** [March 30, 2025, 9:43am UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/12 "2025-03-30T09:43:23Z")

</div>

You don’t need a plugin or a schedule workflow…

If your Question is a record in the DB, store a datetime value in the record. Otherwise just store the start time in a state instead of using a Do Every xx WF.

Whichever you choose just do a comparison check between the value above and the current time. If it’s more than 60 secs then just lock it.

---

<div class="post-metadata">

**Author:** ![mradlane](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@mradlane](https://forum.bubble.io/u/mradlane)\
**Post date:** [March 30, 2025, 11:57am UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/13 "2025-03-30T11:57:04Z")

</div>

Your approach effectively solves the problem by:

1. Storing a precise timestamp (either in the database or in a state)
2. Comparing it with the current time
3. Implementing conditional logic based on this difference

To implement this solution:

```auto
// Option 1: Using a custom state
// At timer start
let startTime = Date.now();
// Store in state
$w.state.startTime = startTime;

// To check (on page load or user action)
let currentTime = Date.now();
let elapsedSeconds = Math.floor((currentTime - $w.state.startTime) / 1000);

if (elapsedSeconds >= 60) {
  // Time's up - lock functionality 
} else {
  // Display remaining time: 60 - elapsedSeconds
}

```

This method works perfectly regardless of whether the user leaves the page or stays on it, as time continues to advance independently of user activity.

No need for complex workflows, plugins, or interval timers that are susceptible to browser throttling. This approach is both simpler and more reliable.

---

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 30, 2025, 5:23pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/14 "2025-03-30T17:23:04Z")

</div>

Hey. Thanks for the suggestion. This seems to be working with Current date/time plugin.

---

<div class="post-metadata">

**Author:** ![durgeshrp](https://avatars.discourse-cdn.com/v4/letter/d/34f0e0/32.png) [@durgeshrp](https://forum.bubble.io/u/durgeshrp)\
**Post date:** [March 30, 2025, 5:26pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/15 "2025-03-30T17:26:12Z")

</div>

I used custom state and stored start time for each question and then did necessary action when one minute (comparing Custom State vs Current date/time) was up. It seems to be working, Thanks.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/bubble/original/3X/2/8/2847faa74692c2ffa5d939d3dc3724cdd060d247.png) [@system](https://forum.bubble.io/u/system)\
**Post date:** [June 6, 2025, 1:11pm UTC](https://forum.bubble.io/t/how-to-build-a-countdown-timer-for-60-seconds/364979/16 "2025-06-06T13:11:53Z")

</div>

Closed on June 6, 2025, 1:11pm UTC

This topic was automatically closed after 70 days. New replies are no longer allowed.
