Hi,
I want to add 1 hour with current time,i done this using following method

date('h:i:s',strtotime('+10 minutes')


but i want to take the current time in a variable and add that time with 1 hour,but that value could not change as the time changes.
help me out to solve this problem.


Regards,
Vidhya

Vidhyaponnusamy,

If I understand correctly, you want to make the calculated value of time+1hr available to other scripts (ie. pages), not just to the page on which the calculation is made.

If this is the case, then there are several ways:

1. Set a session variable (stored server-side for the duration f the user session) : see http://www.w3schools.com/PHP/php_sessions.asp

2. Set a cookie (stored client-side for a duration specified by you) : see http://www.w3schools.com/PHP/php_cookies.asp
Cookie duration is specified as an argument to setcookie(), so you normally wouldn't need to store your calculated time+1hr in the cookie. Instead, store something like notexpired=true, which will be available until the cookie expires.

3. By putting the calculated value into the query string of every href that points back to your site, such that it can be retreived (from $_GET) and acted on server-side. This is normally used as a fallback for browsers with cookie handling turned off. If you decide to do this, then write a funtion appendExpiry(url) which returns the url with the expiry string appended. Then pass your urls through this function before committing to the output stream. This technique is often used for appending a sid (Google appendsid for more information).

Hope this helps.

Airshow

echo $pf_date1 = date("Y-m-d h:i:s"); 
 $dura=1;
$pf_time1 = strtotime("+".$dura."hour");
echo	"<br>".$pf_date1 = date("Y-m-d h:i:s", $pf_time1); ....this value store in database

store $pf_date1 in database or any other variable you want ..
and compare it with current date and time..
i think it solves your problem..

Hi,
you dint understand the problem i think,see now the time is 10 am i am storing this time in one variable say $time,i want to add 1 hour with this variable $time, i done using the following method,but i want to add from the variable,not from the current time and that variable cannot change,that is if i add 1 hour with the variable $time,i got as 11 am,i want to maintain this value throughout the program, i don't want this value to be changed as the time changes.

$time=date('h:i:s',strtotime('+10 minutes'));

Regards,
Vidhya

hi,Vidhya
you code add only 10 minutes

$time=date('h:i:s',strtotime('+10 minutes'));

so change it .so it add 1 hour

$time=date('h:i:s',strtotime('+1 hour'));

store it to database and use it in your program.this value not going to change as time changes..

Member Avatar for diafol

How is your data stored in the db? It should be as a unix timestamp. Use 'time()' to intially store this. To add an hour, just add 3600 to the value in the db. One hour = 60 x 60 seconds.

So when the user 'creates' the time (timestamp), just add 3600 to it and place it in the db. e.g. $mytime = time() + 3600;

Hi,
Thanks for your reply,i got the answer.

Regards,
Vidhya.P

mark thread as solved

Member Avatar for diafol

bandwagon jumper!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.