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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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