tags:

views:

55

answers:

3

i use date function to get day, month and year.

$year = date(y);
$month  = date(m);
$day = date(d);

but my hosting is in another place where i am, so i need to add 11 hours. could you tell me how can i do that? thanks

+5  A: 

Either do

date('Y-m-d', strtotime('+11 hours'));

to add 11 hours or create a DateTime object and change it's timezone where needed

$datetime = new DateTime; // current time = server time
$otherTZ  = new DateTimeZone('America/Los_Angeles');
$datetime->setTimezone($otherTZ); // calculates with new TZ now

or simply set the appropriate timezone with

Gordon
@Gordon is date_default_timezone_set also change the value of NOW() function?
Syom
@Syom `php --rf now` => `Exception: Function now() does not exist` - are you refering to NOW() in SQL queries? You'd have to change that on the Sql server then, too, e.g. http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html
Gordon
You mean Now() as in dev.mysql.com/doc/mysql/en/date-and-time-functions.html ?
VolkerK
@Gordon yes, i mean in sql queries! now i use DATE_ADD(NOW(), INTERVAL 11 HOUR);
Syom
@Gordon where i can see the valid timezone_identifiers? is Armenia/Erevan valid?
Syom
@Syom: see http://docs.php.net/timezones , http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_convert-tz and http://dev.mysql.com/doc/refman/5.1/en/time-zone-support.html
VolkerK
@Syom for PHP use http://de3.php.net/manual/en/function.timezone-identifiers-list.php - also see http://jokke.dk/blog/2007/07/timezones_in_mysql_and_php
Gordon
Thanks for the additional links @VolkerK :)
Gordon
thanks much all of you. it is very useful for me;)
Syom
A: 

you could use http://www.php.net/manual/en/function.date-default-timezone-set.php to set the timezone to what you want

oedo
+1  A: 

See date_default_timezone_set()

Messa