CodeIgniter Forums
Timezone settings are wrong! - 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: Timezone settings are wrong! (/showthread.php?tid=58636)



Timezone settings are wrong! - El Forum - 07-02-2013

[eluser]Unknown[/eluser]
Just realised WHY my site is now showing all datetime variables as -1 hr... I'm using Codeigniter for the first time! (Never had this problem before)

So, I have included the following code in my main index.php file

Code:
/*
    |---------------------------------------------------------------
    | DEFAULT TIMEZONE
    |---------------------------------------------------------------
    |
    | Set the default timezone for date/time functions to use if
    | none is set on the server.
    |
    */
    
    if( ! ini_get('date.timezone') )
    {
       date_default_timezone_set('GMT');
    }



However, it's still showing as -1 hr, so I'm assuming I need to set some sort of default setting for MySQL...

I have included the following line of code in my model:

Code:
function __construct()
        {
            // Call the Model constructor
            parent::__construct();
            $this->db->query("SET time_zone='+0:00'");
        }

Still no difference... Help!

My view code is:

Code:
<h3>&lt;?=date('D, jS F @ g:ia', strtotime($row->datetime))?&gt;</h3>

The $row->datetime variable is nothing more than a DATETIME column value from my MySQL database. The echoed variable in view is ALWAYS 1 hour less than the value in my database...

My model code is:

Code:
function coming_up()
    {
    $query = $this->db->query('SELECT * FROM events WHERE datetime >= NOW() ORDER BY datetime LIMIT 2');
    return $query->result();
    }

HELP!


Timezone settings are wrong! - El Forum - 07-02-2013

[eluser]Syllean[/eluser]
I'm not sure where you're located but I would guess that you are forgetting about daylight savings time. Europe/London time is not GMT time during Daylight Savings, it's GMT+1.