CodeIgniter Forums
Where should I set the default timezone? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Where should I set the default timezone? (/showthread.php?tid=9082)

Pages: 1 2


Where should I set the default timezone? - El Forum - 06-11-2008

[eluser]shuki[/eluser]
Hello,

I am writing an application that will be used in one timezone (Israel) and I wonder where should I set the timezone so that it will affect all the date/time functions?

Code:
date_default_timezone_set('Israel');

Thanks,
Shuki


Where should I set the default timezone? - El Forum - 06-11-2008

[eluser]Prasad.P[/eluser]
You can place that statement in model, if you use or definitely in controller


Where should I set the default timezone? - El Forum - 06-11-2008

[eluser]Michael Wales[/eluser]
I would place it in index.php - right below the error_reporting line (or is that config.php... can't remember - config.php would be a better place, logically).


Where should I set the default timezone? - El Forum - 06-12-2008

[eluser]shuki[/eluser]
Thanks for your answers Prasad.P and Michael Wales.

I suppose that I can create a new library that I will auto load which will execute the
Code:
date_default_timezone_set('Israel');
line.

I will place the value 'Israel' in a config file for that library to keep a separation between parameters and execution. This library could then be extended to cater for other application settings.


Where should I set the default timezone? - El Forum - 08-27-2008

[eluser]aroman[/eluser]
is there any workaround function for date_default_timezone_set( ) tht will works in php4?
-thanks


Where should I set the default timezone? - El Forum - 08-28-2008

[eluser]Crafter[/eluser]
I would avoid interfering with the index file and this may lead to "forgot-to-do-that: syndrome when upgrading,

An autoload library might be more appropriate. One of the config files might be even better.


Where should I set the default timezone? - El Forum - 01-10-2009

[eluser]zea726[/eluser]
Hey where to add this
date_default_timezone_set('Israel');
I tried to add this in a function of a controller.
But as soon as i added this everything went to blank
plz help me....


Where should I set the default timezone? - El Forum - 01-10-2009

[eluser]aroman[/eluser]
[quote author="zea726" date="1231590216"]Hey where to add this
date_default_timezone_set('Israel');
I tried to add this in a function of a controller.
But as soon as i added this everything went to blank
plz help me....[/quote]

You can put that function inside the index.php located in the root of your CI, just below the error_reporting(E_ALL)
This function will works in PHP5 only.

: )


Where should I set the default timezone? - El Forum - 01-12-2009

[eluser]zea726[/eluser]
Hey... Thanks for ur answer...

Somehow its not working...

So I have added a helper file for adjusting the timezone and using it as heleper

Code:
<?php
    function bd_time() {
        return mktime((gmdate('H') . ' GMT')+6, date("i"), date("s"), date("m"), date("d"), date("y"));
    }
?>

if u plz tell me is this right way or not??

Thanks once again.


Where should I set the default timezone? - El Forum - 02-01-2012

[eluser]Andreas Bergström[/eluser]
I have problems with website going blank when adding date_default_timezone_set('Sweden'); to index.php.

I'm on CI 2.1 and NGINX, PHP5, APC. Never experienced this on Apache.

Edit: Found answer here: http://stackoverflow.com/questions/4882790/how-to-set-date-timezone-for-code-igniter-to-work-with-php5-3