Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get the server date and add a couple of hours?

Status
Not open for further replies.

cherrie

Instructor
Feb 5, 2002
1
US
Guys, im a newbie on php.. i want to know how to ad hours into servers date and spit it out on a users browser...


$today = date("Y-m-d");
echo "$today";

This code will print the date. ryt? The question is how to add or subtract hours to $today and spit out in a Y-m-d format so i could use it to query a mysql database..

Tnx and more power..

 
You could use the time() function to create a unix timestamp and then add/seconds the number of seconds you want to need.

The time() function returns the current time in a unix time stamp format.
The date() function will take a optional second variable of a unix timestamp (if the second option is left blank, then the current time is used).

If you wanted to add one hour (3600 seconds) to the current time it would look like this:

$future_time = time() + 3600;
$today = date("Y-m-d",$future_time);
echo "$today";


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top