Link to home
Start Free TrialLog in
Avatar of SevenAteAnthony
SevenAteAnthonyFlag for United States of America

asked on

PHP.ini: Timezone is Incorrect, Though Set Correctly

Hi Experts,

Thanks for reading. When I output the date via date() in PHP, the time is incorrect, though I've correctly set it in my PHP.ini configuration file. Any thoughts on how to fix this?

Avatar of gr8gonzo
Flag of United States of America image

1. What does your setting look like in php.ini?
2. What does your dat() code look like?
3. What does it produce?

It may be an issue of an incorrect timezone in your php.ini, could be that your php.ini file isn't being read properly, or maybe just how you're specifying the date() call.

Also, did you restart the web server after changing the php.ini file?
Avatar of SevenAteAnthony


Hi gr8gonzo,

Thanks for the reply!

1. Please see attached.

$datetime = strtotime( '2012-11-15 10:02:30' );
echo date( 'm/d/y g:i a', $datetime );

Open in new window

3. 11/15/2012 3:02 am

Yes, the server was indeed restarted. Thanks!
@Ray_Paseur This question was created to fix the issue with my PHP.ini file. Thanks, anyway.
Try using that function.  It might be illuminating to see what data you get after this:

Thanks for explaining that out. I've tried it and still to no avail. However, I've discovered that the issue may in fact be with SQL! The calls to the database are saving in the different timezone, but PHP is outputting them as expected.

So how can we tell SQL to save under this timezone, or is this PHP's job?
Avatar of gr8gonzo
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the reply. My SQL insert does not have this. Could you kindly provide an example?

Also, I know you mentioned Server Configuration - is this with Apache? My PHP.ini is configured correctly.

What does your insert code look like? Can you provide an example of code and an example of the final values being inserted?
$entry = mysql_real_escape_string( $_POST['entry'] );
$created = gmdate( "Y-m-d H:i:s" );
$modified = gmdate( "Y-m-d H:i:s" );
mysql_query( "INSERT INTO `entry` ( `entry_id`, `entry`, `created`, `modified` ) VALUES ( '', '$entry', '$created', '$modified' ) ");

Open in new window