Warning about date() function

Hi,

I am trying to follow Kevin’s Book and when I run the following PHP script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Today&rsquo;s Date</title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8"/>
</head>
<body>
<p>Today&rsquo;s date (according to this web server) is
<?php
echo date('l, F dS Y.');
?>
</p>
</body>
</html>

I get the following error:

Warning: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/Helsinki’ for ‘3.0/DST’ instead inC:\WEB\Apache\htdocs\ oday.php on line 12

I tried changing date.timezone in php.ini but it didn’t work.

I have PHP 3.5.6 on my system.

I asume you mean PHP v 5.3.6 and not v3 !

Did you restart your web server after making the .ini change?
It will only pick up .ini changes after a restart.

Rather than use the .ini file, you can add the function date_default_timezone_set() on your web page.

Add the line:
date_default_timezone_set(‘UTC’);
just before your echo date() line.

Essentially PHP is asking you to tell it specifically what type of time zone you want to use before performing any date or time functions.

UTC sets it to the universal time zone. Set this to whatever time zone you want the php script to process in.

For a list of time zones, see the function ref at php.net
PHP: date_default_timezone_set - Manual
PHP: List of Supported Timezones - Manual

Cheerz,
Wil.

Hi wil,

Sorry it is 5.3.6, I mistyped. And it worked after a restart just as you suggested. Also, the date_default_timezone_set() function worked as well. But what makes the function a better option?

The function gives you more specific control. I guess there could be times where you’d want to process different time zones in the same php script.

Also helps prevent ur customers playing around with .ini settings.

Wil.

Thanks Wil,

That makes sense.

Nail