tags:

views:

232

answers:

3

Hi, How can I retriving CURTIME() from server by adding 3hrs and show it in PHP page. Thanks in advance.

+1  A: 

in MySQL:

SELECT CURTIME()

Then in PHP:

// get the SQL query result in $curtime, then:
$t = strtotime( date('Y-m-d ') . $curtime );
$t = strtotime( "+3 hours", $t );
echo date( 'H:i:s', $t);

But if the time on the PHP server is the same, you could do that directly:

echo date( 'H:i:s', strtotime( '+3 hours' ) );
streetpc
+1  A: 

The time calculation is done this way:

$unixTime = time() + 60 * 60 * 3;
echo gmdate('Y-m-d H:i:s', $unixTime);

If you intend to provide the time for a different time zone, though, you should have a look at the DateTime class in php.

EDIT

If you need to get the time from a mysql server, the $unixTime is calculated this way (Do not forget to insert error handling for the mysql functions):

$resultRow = mysql_fetch_row(mysql_query('SELECT UNIX_TIMESTAMP() + 60 * 60 * 3'));
$unixTime = $resultRow[0];
soulmerge
+1  A: 

If you want to you can let MySQL handle the time arithmetic

SELECT Time(Now()+Interval 3 hour)
see http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add

VolkerK