Adjust Server timezone ( time zone ) by adding helper file in CodeIgniter (code igniter, codeigniter, ci )

It has been seen that often the server is located in differnt timezones than ours….. Its been too tough to change the timezones in CodeIgniter for me. To resolve this problem we can add a simple helper file. For this you need to do the following steps.

Step 1. Create a folder in your applications folder named ‘helpers’

Step2. Save a file with named ‘zea_helper.php’ containing

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

in the above created ‘helpers’ folder.  I have used +6 bceause bangladesh time is GMT 6+, if your time is GMT -4 you should write “(gmdate(‘H’) . GMT’)-4,” instead (gmdate(‘H’) . ‘ GMT’)+6,

Step3. Go to your autoload.php in config folder and change the line $autoload['helper'] = array(”); to $autoload['helper'] = array(‘zea’); and save the file.

Step4. Now just load the helper just like other helpers in your controller like $this->load->helper(‘zea’);. and start using it as a helpers

ex: echo date(“F j, Y, g:i a”,bd_time());

dont forget to load the helper in the controller.

5 thoughts on “Adjust Server timezone ( time zone ) by adding helper file in CodeIgniter (code igniter, codeigniter, ci )

  1. deven

    I think you have already loaded the helper in the autoload , so there is no need to load it again in the controller.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>