April 7, 20179 yr Hi Gang, Bit of a weird one, hoping someone can help. I've a 1 hour gap (UTC/BST) between SQL and PHP. $q = "UPDATE `table` SET `updated` = NOW() WHERE `id` = ?"; // SQL table updates correctly with BST e.g. 2017/04/07 09:42:00, however the following at the same time... echo date("Y-m-d H:i:s"); // This shows 2017/04/07 08:42:00 which is UTC. Might be a bit green here, I always thought SQL time and php time would be the same as it would use system clock or am I missing something? Cheers. Edit: So I made a function for displaying current London time. function londonTime() { $a = new DateTime("now", new DateTimeZone("Europe/London")); $a->setTimestamp(time()); return $a->format("Y-m-d H:i:s"); } This works, but still not 100% sure why SQL takes BST into account so any explanation would be great, things like this niggle me Edited April 7, 20179 yr by BrowserBugs
April 7, 20179 yr Don't get me started on timezones.You could try setting the timezone manually in PHP, that way you don't have to worry about the two being in sync, and you can do things like let the user dictate the timezone, if that's ever a requirement. date_default_timezone_set('Europe/London'); http://php.net/manual/en/function.date-default-timezone-set.php
April 7, 20179 yr Not sure if this helps as I don't mess with PHP much, if at all these days but moment.js has a timezones module which is really nice, maybe you can use that and post the result to your server. Of course if you were using Node you could just import it and use it directly
April 7, 20179 yr Author Cheers all. Will look at the ini just found it odd that the db must be set to London and the ini might not be, would have thought set both or leave both in UTC. Inherited projects ... gotta love em
April 7, 20179 yr Cheers all. Will look at the ini just found it odd that the db must be set to London and the ini might not be, would have thought set both or leave both in UTC. Inherited projects ... gotta love em You can set the ini value by doing ini_set('date.timezone', 'America/New_York'); or get the value of the current setting in the ini file echo ini_get('date.timezone');
Create an account or sign in to comment