Note that there are some explanatory texts on larger screens.

plurals
  1. POCodeigniter timezone mysql settings
    primarykey
    data
    text
    <p>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)</p> <p>So, I have included the following code in my main index.php file</p> <pre><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'); } </code></pre> <p>However, it's still showing as -1 hr, so I'm assuming I need to set some sort of default setting for MySQL...</p> <p>I have included the following line of code in my model:</p> <pre><code> function __construct() { // Call the Model constructor parent::__construct(); $this-&gt;db-&gt;query("SET time_zone='+0:00'"); } </code></pre> <p>Still no difference... Help!</p> <p>My code is:</p> <pre><code>&lt;h3&gt;&lt;?=date('D, jS F @ g:ia', strtotime($row-&gt;datetime))?&gt;&lt;/h3&gt; </code></pre> <p>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...</p> <p>My model code is:</p> <pre><code>function coming_up() { $this-&gt;db-&gt;query("SET time_zone='+0:00'"); $query = $this-&gt;db-&gt;query('SELECT * FROM events1 WHERE datetime &gt;= NOW() ORDER BY datetime LIMIT 2'); return $query-&gt;result(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload