1

I want to set a specific folder to another timezone in the php.ini file so I don't have to set it manually in each file within the folder.

[Date]
date.timezone = Europe/Berlin

Folder[Date] /* something like this? */
date.timezone = America/New_York
John Smith
  • 1,750
  • 3
  • 18
  • 31

4 Answers4

2

You should be able to use .htaccess to set the default timezone on a per directory basis.

Just add

php_value date.timezone "America/New_York"

to an .htaccess file in that directory and make sure your server supports per directory configuration.

Orangepill
  • 24,500
  • 3
  • 42
  • 63
1

Use date_default_timezone_set in the scripts in that folder.

You can also set it in htaccess:

php_value date.timezone "America/New_York"

For this to work, you need to use mod_php in Apache. See also this question.

Community
  • 1
  • 1
GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • for every file? so... include a file that sets this in every file? that feels very redundant. – John Smith Jul 22 '13 at 20:51
  • 2
    Not every file, but every entry point. If every request runs through a single index.php, you can put it in there. If every script includes a general purpose library for connecting to a database or so, you can put it in there. If your scripts are actually completely separate scripts with nothing in common, then I think you're one of the very few. Most sites run through a common entry point script. – GolezTrol Jul 22 '13 at 20:53
0

You can probably also use in the .htaccess file:

SetEnv TZ America/New_York

Which should work on every system, php_value may not work on certain servers. But I would really recommend using the normal php function:

date_default_timezone_set('America/New_York');

http://php.net/manual/en/function.date-default-timezone-set.php

in a specific file that has the configuration specific to your script, and then just include the file in your other files.

user816624
  • 15
  • 1
  • 6
0

These answers are all correct when using a webserver, however this doesn't work running a PHP CLI script, for ie. a cronjob. PHP would use the date.timezone setting defined in php.ini.

Best practice would be, to just call date_default_timezone_set on top of your application wrapper/bootstrap file.

date_default_timezone_set('America/New_York');
Tim
  • 2,805
  • 25
  • 21