Stop Warning: date() [function.date]: from localhost

30,364

Solution 1

The reason it is happending on one server and not the other is the php.ini setting date.timezone=.

You would still need to pick an actual value though. You assuredly don't have one. Or in the wrong php.ini version (there's one for CLI and one for mod_php).

Solution 2

As the other posters have mentioned, setting date.timezone in the php.ini file is the way to go. If you are still seeing the error about needing to set it, did you restart your web server (apache, IIS, etc) after setting the php.ini?

Also, the warning from phpinfo means the rest of the output should still be showing. Make sure you're editing the correct php.ini file according to the phpinfo() output.

That will likely get you working as you'd like.

Solution 3

to remove this warning from your project

There are 2 ways to do so...

1) date_default_timezone_set('Asia/Kolkata'); include this file in your index.php file This will work only for your current project

2) date_default_timezone_set('Asia/Kolkata'); or inlude this file in your php.ini file This will work for every project

thnx :)

Share:
30,364
X10nD
Author by

X10nD

Updated on July 09, 2022

Comments

  • X10nD
    X10nD almost 2 years

    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 ............

    There are many web applications that spring up this particular error. I could set

    date_default_timezone_set('America/Los_Angeles');
    

    But that is not the solution I am looking for.

    Can I do something from system level. It happens only on LOCALHOST not on the actual production server.

    Default set in php.ini is date.timezone = America/Los_Angeles

    [update] edited php.ini

    Warning: phpinfo() [function.phpinfo]: 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

  • X10nD
    X10nD over 12 years
    Default set in php.ini is date.timezone = America/Los_Angeles
  • X10nD
    X10nD over 12 years
    phpinfo() ERROR --- Warning: phpinfo() [function.phpinfo]: 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.
  • X10nD
    X10nD over 12 years
    phpinfo() ERROR --- Warning: phpinfo() [function.phpinfo]: 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
  • DaveRandom
    DaveRandom over 12 years
    Look at the path of php.ini as displayed by the output of phpinfo() - ignore the error for now - and make sure you have defined the default timezone in that php.ini file.