By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Problem in setting timezone

P: 49
Hi everyone

I want to set timezone (US/Central). It is working fine on my local computer but when I upload the code on web server It is giving me error

Fatal error: Call to undefined function: timezone_open() in

Here is the code

Expand|Select|Wrap|Line Numbers
  1. $tz1 = timezone_open("US/Central"); 
  2. $ts = date_create("2008-08-19 12:19:21", $tz1);  
  3. echo $ts->format(DATE_RFC822), "<br/>";$ts->setTimezone($tz1); 
If anyone could help me

Aug 27 '08 #1
Share this Question
Share on Google+
7 Replies

Expert Mod 5K+
P: 8,639
what php version does the server use? timezone_open() requires PHP 5.1.0 at least.
Aug 27 '08 #2

P: 3
Hi all,

I have the same error log:
Expand|Select|Wrap|Line Numbers
  1. Fatal error: Call to undefined function: timezone_open() in 
with simple script:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $t=time();
  3. echo($t . "<br />");
  4. $date = timezone_open($t);
  5. echo $date;
  6. ?>
and PHP 5.2.14 (cli) (built: Aug 27 2010 16:40:16)

Can someone give me a tip?


Sep 22 '10 #3

Expert 5K+
P: 5,058
Are you 100% sure about that version number? (A 110% sure?) - I've lost count how many hours I've wasted because I assumed things like that without properly testing for it :)

That said, did you try bypassing the alias function and just using the normal OOP method?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $d = new DateTimeZone(time());
  3. echo $d;
  4. ?>
Sep 22 '10 #4

P: 3
Hi Atli,

yes, I'm sure:
Expand|Select|Wrap|Line Numbers
  1. # php -v
  2. PHP 5.2.14 (cli) (built: Aug 27 2010 16:40:16) 
  3. Copyright (c) 1997-2010 The PHP Group
  4. Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
  5.     with the ionCube PHP Loader v3.1.29, Copyright (c) 2002-2007, by ionCube Ltd.
I try your script and I obtain this error log
Expand|Select|Wrap|Line Numbers
  1. PHP Fatal error:  Class 'DateTimeZone' not found
I don't understand why
Sep 23 '10 #5

Expert 5K+
P: 5,058
That's really odd. According to the manual entry for that class it is supposed to be built into the PHP core since 5.2.0. Could it be that there is something special about your build? How did you install it?

Also, looking at this more closely, you are not using the class as it should be used. The constructor takes a timezone name, not a timestamp. That is, you should pass it a string like: "GMT", "UTC", or even something like: "Iceland" or "America/New_York".
Sep 23 '10 #6

Expert 5K+
P: 6,050
Are you using the CLI PHP binary to test this, or are you testing through your webserver? Many times have we seen people give us the version of their CLI PHP binary, assuming it to be the same as the binary used by their webserver (it is typically not).
Sep 23 '10 #7

P: 3
I'm sorry if I used the class as it should be used.
Now, before to reply to thred, I used other Centos5 server with PHP4 and I used these command-line:
Expand|Select|Wrap|Line Numbers
  1. # yum update
  2. # php -v
  3. PHP 5.1.6 (cli) (built: Mar 31 2010 02:44:37) 
  4. Copyright (c) 1997-2006 The PHP Group
  5. Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
  6. # more test.php
  7. <?php
  8. $date = timezone_open('UTC');
  9. echo $date;
  10. ?>
  11. # php test.php
  12. PHP Fatal error:  Call to undefined function timezone_open() in ... on line 2
So that I used two guides:
* to update PHP from 5.1.6 to 5.2.10 but I had again the error log
* to update PHP from 5.2.10 to 5.2.14 but I had again the error log

Update from 5.1.6 to 5.2.10 was completed only after I erased php-sqlite2 (yum erase php-sqlite2).
Sep 24 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.