Jump to content
xisto Community
Sign in to follow this  
it01y2

Time Help Time Help

Recommended Posts

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

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

Share this post


Link to post
Share on other sites

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.