views:

374

answers:

4

Hi -

When I use current_timestamp with MySQL, I get the correct time, but when I use

$mysqldate = date( 'Y-m-d H:i:s' );

I get the date with with an hour delay (eg, 4:42 PM is 5:42 PM). I understood that both function use the server's local time - can someone explain the difference?

Thanks.

+1  A: 

Take a look at this article: http://www.devarticles.com/c/a/MySQL/Practical-Date-Time-examples-with-PHP-and-MySQL/

Ropstah
+1  A: 

Maybe your PHP server thinks it's in a different time zone or it uses different locale and daylight saving time rules.

Piskvor
how do i get PHP to give me the default, server time that's listed on server's computer? PHP's date.timezone isn't set
daniel
+2  A: 

There are php locale settings, it takes it from php.ini, not from system time

Svetlozar Angelov
+7  A: 

The global system time will be set via the /etc/localtime file, which will be either a symlink or a copy of a zone file from /usr/share/zoneinfo/ on most systems. Applications will use this as their default.

PHP can override this in a couple different ways:

  1. date.timezone in php.ini
  2. setting the TZ environment variable, e.g. putenv("TZ=US/Central");
  3. date_default_timezone_set function (in PHP >= 5.1.0)

MySQL can override this by running the following query immediately after connecting:

SET time_zone = 'US/Central'
Gabe Martin-Dempesy