Page 1 of 1

date_default_timezone_set function not working

Posted: Fri Mar 13, 2009 10:43 am
by oboedrew
I am attempting to use the date_default_timezone_set function to override my web host's default timezone setting so that when I use the date function it returns a date that is correct for a specified timezone. However, this function is not working. I ran these two tests:

Code: Select all

 
Test One
 
date_default_timezone_set(America/New_York);
$timezone=date_default_timezone_get();
$date=date('Y-m-d H:i:');
echo
    "$timezone $date"
;
 

Code: Select all

 
Test Two
 
date_default_timezone_set(America/Los_Angeles);
$timezone=date_default_timezone_get();
$date=date('Y-m-d H:i:');
echo
    "$timezone $date"
;
 
In both tests, the output is the same: EST5EDT 2009-03-13 11:35.
EST5EDT is the default timezone set by my web host. The PHP version is 5.2.6.

Can anyone explain to me why date_default_timezone_set() is not working?

Thanks,
Drew

Re: date_default_timezone_set function not working

Posted: Fri Mar 13, 2009 1:53 pm
by requinix
Is that code copy/pasted from your script?

The city is supposed to be a string. You gave it two constants, one divided by the other.
The fact that you didn't see the two E_WARNINGs doesn't mean the code is correct.

Code: Select all

date_default_timezone_set("America/Los_Angeles");

Re: date_default_timezone_set function not working

Posted: Fri Mar 13, 2009 3:04 pm
by oboedrew
Oops! That fixed it.

Thanks,
Drew