Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5990831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:18:00+00:00 2026-05-22T23:18:00+00:00

In response to the announcement that WordPress 3.2 (due later this month) will require

  • 0

In response to the announcement that WordPress 3.2 (due later this month) will require PHP 5.2.4+, I upgraded my Windows test machine today from XAMPP 1.5.5 to 1.7.4, which in turn bumped me up from PHP 5.2.0 to 5.3.5.

I’ve got just about everything working again, but one test page is behaving strangely. I have a MySQL table with tz identifiers by country code and the following script determines and displays the current time in each of the timezones:

<?php
  echo "<table>";
  $result = mysql_query("SELECT * FROM zone_data ORDER BY `id` ASC;");
  while ($row = mysql_fetch_assoc($result)) {
    putenv("TZ=".$row['zone_name']);
    echo "<tr>";
      echo "<th>".$row['zone_code']."</th>";
      echo "<td>".$row['zone_name']."</td>";
      echo "<td>".date("D j M Y / H:i T",$_GET['t']);
        if (date("I") == 1) { echo "*"; } // asterisk if in DST
      echo " (".date("P",$_GET['t']).")</td>";
    echo "</tr>";
  }
  echo "</table>";
?>

The expected output, which runs just fine on the production server in PHP 5.2.17, should be along the lines of:

Z   Etc/UTC          Fri 3 Jun 2011 / 03:22 UTC (+00:00)
AD  Europe/Andorra   Fri 3 Jun 2011 / 05:22 CEST* (+02:00)
AE  Asia/Dubai       Fri 3 Jun 2011 / 07:22 GST (+04:00)
AF  Asia/Kabul       Fri 3 Jun 2011 / 07:52 AFT (+04:30)
AG  America/Antigua  Thu 2 Jun 2011 / 23:22 AST (-04:00)
...

…but instead I’m told that the time is the same as my system time, America/New_York (currently UTC-4) in every zone:

Z   Etc/UTC          Thu 2 Jun 2011 / 23:22 EDT* (-04:00)
AD  Europe/Andorra   Thu 2 Jun 2011 / 23:22 EDT* (-04:00)
AE  Asia/Dubai       Thu 2 Jun 2011 / 23:22 EDT* (-04:00)
...

Now, I had noticed that line 1001 of the new php.ini installed with XAMPP 1.7.4 had originally contained date.timezone = Europe/Berlin, so I’d replaced it with date.timezone = America/New_York. But in both cases, every instance of the date() function is being dictated by this setting regardless of anything I’ve said otherwise with putenv(). The same holds true for all other pages using date() (although gmdate(), obviously, returns GMT as expected).

I tried commenting out that line, but PHP 5.3.5 threw lovely errors saying that it’s “not safe to rely on the system’s timezone settings” and that I’m required to use the date.timezone directive in php.ini, even though I always use putenv() when I use date() or similar functions.

It’s a bit frustrating to be forced to make a “super-global” setting, especially for a case like this where the whole point is to temporarily enter a new TZ environment and glean some useful information from it.

So… Is there any way I can have the date.timezone directive behave as a default that is overridable by putenv() such that the latter isn’t completely ignored? Is there anything else you can think of that might be causing the unexpected/bizarre behavior outlined above?

I’m inclined to believe that this is just some server setting that needs to be changed to allow putenv() to continue working in PHP 5.3.5 as it did in 5.2.0 (and does in 5.2.17). Of course, if there’s a “better way” altogether, I wouldn’t mind hearing about it (I always like learning new things!). But mostly I want my old code to work on my new install.

Let me know if you need any more information about my setup.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:18:01+00:00Added an answer on May 22, 2026 at 11:18 pm

    The TZ environment variable is ignored under PHP 5.3. (The PHP manual page for date_default_timezone_get describes the order the various settings will be considered in, including that TZ only applies for PHP < 5.3).

    Simple solution: instead of putenv, use date_default_timezone_set to set your different timezones.

    The above is the most direct replacement for putenv, but the DateTime class offers a better way to do date operations in different timezones while not affecting the “current” timezone for other date operations. DateTime‘s constructor can take a DateTimeZone argument that only affects the timezone for that particular object (this can also be set with setTimezone():

    $date = new DateTime(null, new DateTimeZone('Europe/Andorra'));
    echo $date->format(/* your date format */);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In @mmalc's response to this question he states that In general you should not
I'm implementing a Announcement system that is loosely based on this article: https://web.archive.org/web/20211020111733/https://www.4guysfromrolla.com/articles/110409-1.aspx One
In response to an event this is executed: $.getScript('nav.php?node=' + node); nav.php returns the
Based on the response to this question: Why does C++ have header files and
Every Hello has a response. Second TTY will send a hello to the sender
Response example for MD5 hash found, for example http://md5.noisette.ch/md5.php?hash=2a0231531bc1a7fc29e2fa8d64352ae9 : <md5lookup> <hash>2a0231531bc1a7fc29e2fa8d64352ae9</hash> <string>noisette</string> </md5lookup>
Ajax response I am getting is always empty! Interestingly, if I copy paste that
This is the response I'll be getting: <?xml version=1.0 encoding=utf-8?> <rsp stat=ok> <image_hash>cxmHM</image_hash> <delete_hash>NNy6VNpiAA</delete_hash>
From a response to some question yesterday, I learned that it is nonportable and
I need to parse a JSON Response that looks like: {key1: value1, key2: value2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.