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

0 favourites
  • 5 posts
From the Asset Store
[C2] [C3] support C3 build service | support Banner ads, Interstitial ads, Rewared video ads.
  • 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))

  • 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.

    drive.google.com/file/d/1njkOW5E93Z6dAKfrj2u2FB2pDBqoCkmo/view

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)