0

On stock market application we found a bug that appears on day change minus time offset. i.e. for our case it happens on server time 00:00 to 02:00 where we're taking time GMT+2. php is returning wrong date values out of time stamp. for instance yesterday night around 01:15 php returned 28/08/2014 even if the actual date is 29/08/2014. later I found php always consider timestamp as GMT for date so while MySQL returning right date value out of timestamp, php doesn't. and because of that the bug is appearing for sometime.

I searched on internet about it. there's some mention of such behavior of php, but mostly they gave solution to change timezoen in php.ini. but that solution can't be used here.. Does anyone know the solution?

  • Your MySQL instance and PHP server instance have different timezones, you need to correct for this, by either configuring both to same time zone, or implement a solution in code to accommodate the difference. I would suggest the former. I typically just set all server configuration to GMT and handle timezone conversion for display purposes in the application layer. – Mike Brant Aug 29 '14 at 14:29

1 Answers1

1

This is the function you need - http://php.net/manual/en/function.date-default-timezone-set.php

date_default_timezone_set('America/Los_Angeles');

Or in the php.ini file - add on top

date.timezone = "US/Central" //or your city

You can also use Etc/GMT 2

mariobgr
  • 2,143
  • 2
  • 16
  • 31
  • It would be `Etc/GMT-2` to get a +2 fixed offset zone (the signs are inverted). But I would recommend against using those, as they don't account for DST. – Matt Johnson-Pint Aug 29 '14 at 17:13