it01y2 0 Report post Posted November 10, 2006 I need help to add two timestamps together. Basically I have the current time by usidng the time() function and I want to add the time to attack players on the game I am playing But i am stuck adding the timestamps together, it does not workIf anyone could help me I would be much abliged. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted November 10, 2006 Check this out: <?php$time_interval = 12; // time_interval in hours$some_time = ($time_interval * 60 * 60); // in seconds$current_time = time(); // as unix timestamp$attack_time = $current_time + $some_time; // add them togetherecho 'Current time as UNIX: ' . $current_time . '<br />'; // output to confirmecho 'Time Interval as UNIX: ' . $some_time . '<br />'; // output to confirmecho 'Attack time as UNIX: ' . $attack_time . '<br />'; // output to confirm$old_time = date('Y-m-d@h:i:sa', $current_time); // output to confirmecho 'Time Now : ' . $old_time . '<br /><br />'; // output to confirm$attack_time = $current_time + ($time_interval * 60 * 60);echo 'When do I attack??? : ' . date('Y-m-d@H:i:sa', $attack_time) . ' local';?>Hope this works for you or explains enough for you to get what you need.There are ways to shorten it down and get the same results, but I thought you might learn more if the code was broken down to multiple steps. Also, I didn't know if you wanted UNIX or 'readable' time formatting. This gives you an example of each... Share this post Link to post Share on other sites
it01y2 0 Report post Posted November 13, 2006 This is a very good script, But I want to load the attack time from a variable how could I do this?ThanksRob Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted November 13, 2006 If you know when the Attack is going to take place, why do you need to add it to the current time? Maybe I don't understand something?Do you want to subtract the two to know how many hours away the Attack will be? Share this post Link to post Share on other sites
it01y2 0 Report post Posted November 13, 2006 Ok this is in detail:People will select how many troops they will send to attack the other player. So the time is created by timing the unit number by the time (which is 00:01:13 per unit)so $time = $_POST[unitsammount] * 00:01:13then I need to add the time($time) to the current time and input it into the database to give me the time which the attack will arive the other player.Thanks Rob Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted November 13, 2006 http://ca3.php.net/manual/en/function.time.phpI don't mind helping, but at some point I have to point you onto the path and let you make your own mistakes. There is enough info in the previous post and this reference to have you work it out yourself. Share this post Link to post Share on other sites
it01y2 0 Report post Posted November 13, 2006 Hi again What does the error: Resource id #18 mean? Share this post Link to post Share on other sites