Countdown that repeats every week

I use nightbot on my discord channel. I used custom command to display a countdown to the next sunday at 7AM whenever anyone types !raid.
I would like this countdown to work for all sundays instead of a date that I have to update every week (at the moment it is set to 24th June instead of set to Sunday). How can i achieve this?

You can use the eval variable to calculate next Sunday’s date.

$(countdown $(eval h=7+4;n=new Date();s=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()+(7-n.getUTCDay())%7,(h%24+24)%24));if(s<n)s.setDate(s.getDate()+7);s.toLocaleTimeString("en-US",{hour12:true,month:"numeric",day:"numeric",year:"numeric"}).replace(/\//g," ").replace(/,/g,"").replace(/(?=\b\d\b)/g,"0")+" "+Intl.DateTimeFormat().resolvedOptions().timeZone))

Notice the h=7+4 in the above code. This sets the countdown time to 7 AM in Eastern time.

If you’re not using Eastern time:

  • Go to and find the text that says “UTC is number hours ahead of/behind location.”
  • Replace the 4 with number
  • If it says “behind”, also replace the + with -

Hi I tried adding this (with h=7+5.5 for India). but it says invalid timezone specified. Any idea how to fix?

Thanks in advance

You can use this for India Standard Time:

$(countdown $(eval h=7-6;m=30;n=new Date();s=new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth(),n.getUTCDate()+(7-n.getUTCDay())%7,(h%24+24)%24,(m%60+60)%60));if(s<n)s.setDate(s.getDate()+7);s.toLocaleTimeString("en-US",{hour12:true,month:"numeric",day:"numeric",year:"numeric"}).replace(/\//g," ").replace(/,/g,"").replace(/(?=\b\d\b)/g,"0")+" "+Intl.DateTimeFormat().resolvedOptions().timeZone))
1 Like

Thanks, that works :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.