# How do I use the Date plugin to make a countdown with days and hours?

0 favourites
• 5 posts
From the Asset Store
Two tracks for different genres of gaming. A bit futuristic vibe in the music.
• Hi! The built in timer expressions are great for countdowns but I'm missing days and limiting hours to 24 hours to count down. Right now hours is the biggest value and shows hundred hours instead of days.

How can I convert the hours to days and change the hour countdown to 0-23?

(for days I used floor(hoursleft/24))

#### Tagged:

• Try this out but replace NextBirthDay

int(Date.ToTotalHours(abs(Date.Difference(Date.Parse(Date.ToDateString(Date.Now)), Date.Parse(Date.ToString(NewDate))))) / 24)

A quick forum search could have lead you to a post where I answered almost this exact question. Here is the project I built to answer it. This project shows a countdown to a persons next birthday.

• Thanks. But how can I limit the hours to show only 0-23 for every day passing?

• Just use the % (modulo) operator. It returns the remainder of a division. For example:

28 % 24 = 4

In the case of the example I gave you, The last line sets the DaysTillBDay equal to:

Date.ToTotalHours(abs(Date.Difference(Date.Parse(Date.ToDateString(Date.Now)), Date.Parse(right(NextBirthDay.Text, 11))))) / 24

For the remaining hours, you would just set it equal to:

Date.ToTotalHours(abs(Date.Difference(Date.Parse(Date.ToDateString(Date.Now)), Date.Parse(right(NextBirthDay.Text, 11))))) % 24

Even if you didn't know about the % operator though, you could just do this:

totalHours - (DaysTillBDay * 24)

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I heard about the modulo operator but couldnt find it last time I searched the manual and never used it. I will try it, thanks!

• 5 posts