Jump to content

Php/sql date/time question


apw

Recommended Posts

My question is about .. When player hits the next-turn button the players pfile in the sql-database should stamp the time the player hit the button, which it does however along that line i also need an additional 20-minutes or so added to the stamped time then when the real-time reaches the time that was an additional 20-minutes my script tells player that their army has returned! Is that possible?

Link to comment
https://forums.phpfreaks.com/topic/112083-phpsql-datetime-question/
Share on other sites

You can use the ADDTIME function in mysql (or a similar one if you aren't using mysql) to add to the time when you put it in the db.

"UPDATE players SET ArmyBackAt = ADDTIME(NOW(), '00:20:00') WHERE PlayerID = $id";

 

Then when a player tries a link, check if NOW() is past that time; if it is, their army is back.

I think you're looking for an offset. Why not just insert the time that the button was clicked into the database, and then check the current time to see if it's been more than 20 minutes since they hit the button. This is the way I would do it, however if people don't refresh the page for 20 minutes then they wouldn't be updated about the status of their army. Unless you had some kind of automated refreshing function. To do this you should either use an HTTP refresh, javascript refresh or use PHP's header() function (not sure if it's possible with header(), I don't see no reason why not).

 


$offset = 20 * 60; // 20 minutes
$old_time = 15 * 60 * 60; // 3pm
$time = time(); // current time

if(($time - $old_time) < $offset) {
 // refresh page...
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.