Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

SQL vs PHP: DateTime Issue

Featured Replies

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 by BrowserBugs

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

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 :p

  • 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 ;)

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.