This article is now available in our new knowledge base: Set Up Time Zones for PHP on IBM i
PHP scripts return the wrong time of day, unless the time zone is set correctly.
This article explains how to set the correct time zone for IBM i and for PHP.
Zend Server for IBM i version 6 or higher. IBM i, any currently supported version. PHP, any currently supported version.
There are several settings that affect the time zone, including the setting for your IBM i, the setting for FastCGI, and the setting for PHP. This article tells how to make each of these settings, and also how to set the time zone in your script to override the default. There is also a sample script that shows a formatted date and time.
Set the time zone for IBM i
To set the time zone on your IBM i, please set the system value QTIMZON. Some available values for the U.S. are:
|Time zone description||New 2007 rules QTIMZON value|
For example, if you are in the Pacific time zone, you would use this command:
CHGSYSVAL SYSVAL(QTIMZON) VALUE(QN0800PST2)
If you change this value, you should also reset system value QTTIME to the correct time, using a six digit 24 hour time. For example, if the time is 4:35 in the afternoon:
CHGSYSVAL SYSVAL(QTIME) VALUE('163500')
You can find a complete list of supported time zones at IBM i info center - Timezone .
Set the default time zone TZ variable in the FastCGI configuration
Usually the installer takes care of this setting, but you can check to verify it, and adjust if needed. Please find this file and open for browsing/editing:
For Zend Server 9 and later:
For Zend Server versions 6 through 8.5:
This is a configuration file, so if you do make any changes, please BACK IT UP first. That way, if any change makes it not work, you can replace the changed file with the back up and get running again quickly. If you make any changes to this file, you must restart Apache for the change to take effect.
The fastcgi.conf has a very long first (non-comment) line. Everything on this line has to be on the first line, so it has to be this long. Please be careful not to inadvertently insert any line breaks into this line.
Out at the very end of this line, you can usually find the TZ environment setting. If it is not at the end, check the whole line to see if it is anywhere else. If there is no TZ setting, you should add one.
The clause that sets the TZ environment variable will look similar to this one:
This example shows that the standard time zone is Pacific Standard Time (PST), the offset from UTC (or CUT) is 8 hours, and the daylight time zone is Pacific Daylight Time (PDT). The next two items define the start and end date for daylight savings time in a month, week, day of the week format. So, daylight savings starts in the third month (March), the first week of March, and on Sunday, the zero day of the week.
You can learn more about setting the TZ variable and see charts of the available time zones here:
You don't need to set up an environment file, so ignore all that. This is just the page that seems to have the best documentation of the TZ variable, so please look at that information.
One important difference in the way the documentation presents the time zones is that they do not use the less than and greater than signs (<>) on the time zones. We use them in the FastCGI configuration because it somehow improves the ability of PASE to parse them correctly. So, for example, in the documentation you would see this for Central Europe:
But in the fastcgi.conf file, you would add the punctuation, like this:
Here are some examples for the continental U.S.:
|Timezone||Value to use|
Set the default time zone for PHP
To set the time zone for PHP, For Zend Server, please go into the Zend Server User Interface in your browser, navigate to Extensions -> PHP, find 'date' on the list, and single-click it to expand the directives.
Set the time zone (date.timezone) using the country/city code appropriate for your area. Here are some examples for the continental U.S.:
|Timezone||Value to use|
For example, if you are in the Pacific time zone, use the value America/Los_Angeles. Do not enclose the value in quotes. You must restart Apache for this change to take affect.
You can find a complete list of supported time zones in the PHP manual at List of Supported Time Zones .
Log out of the Zend Server User Interface and log back in
After any changes to the time settings are made, you may need to log out of the Zend Server User Interface and log back in to see the correct time displayed there.
Setting the time zone in your script
You can override the default PHP time zone by using the date_default_timezone_set() function in your script. Details can be found in the PHP Manual at PHP Manual date_default_timezone_set function .
Simple script to demonstrate the time zone setting
This simple script will present the date and time nicely formatted. It can be useful to demonstrate that the time zone settings are working correctly.
// Example to show date and time in a nice format
echo "The current date and time is ";
echo date("F j, Y, g:i a");
echo ", in the timezone ";
// Show date and time from PASE
An example of the output:
The current date and time is June 29, 2016, 9:01 am, in the timezone America/Los_Angeles
Wed Jun 29 09:01:59 PDT 2016