Copephobia
Copephobia

Reputation: 37

Number of seconds until every 20 minutes

For a game I'm making, each turn is at :00, :20, and :40 past the hour. I am trying to create a countdown that will display the number of minutes (and eventually seconds) to the next turn.

My current approach is to store the time of the next turn in a database, then doing

$time = time() - $time_to_turn

where time_to_turn is the database entry of the next turn time.

Is there a way to not use the database?

Upvotes: 1

Views: 221

Answers (1)

erisco
erisco

Reputation: 14329

Try $minutesRemaining = 20 - date('i') % 20; or $secondsRemaining = 1200 - date('s') % 1200

Upvotes: 2

Related Questions